in reply to Making commond for large number of files

Hi,

Here are some of ideas,

1.Search for the string 'SCF Done=\d+'in each file, use this node for how to find a string in a file from this node how can i search a text file for a string and print every occurence of that string, do it for all the file and hold the data in a hash like below,

my %SCF_Done=('FileName1.txt'=>{energy_value=>123,line=>"line from eac +h file"});

From here you do whatever you want, sort the energy_value and find the lowest value of energy and do split on the line and get each column and do subtract on $3 and save to a file.


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: Making commond for large number of files
by acrobat118 (Initiate) on Apr 17, 2015 at 17:26 UTC

    I have been successful in looping over all the files by grep  grep "SCF Done" $files|awk "{print \\\$5}"`;. It has given the SCF Done from each file. Now I can search my self among the SCF Done list of 200 files that which one has lowest "SCF Done". I have fonud a file. But problem is that I want to use that file in next step. Each file has a column with electron delocalization papameter that a long column with number but column header is (EDu). I want to code for:

    1. Find the file among 200 files which has lowest SCF Done.

    2. Then I want to use the (EDu) column of this minimum SCF Done file from step 1 to get the difference of (EDu) of all remaining 199 files and want to get result in a text file. For example if (EDu) of minimum SCF Done file be (EDu)min. I want (EDu)min - (EDu)1, (EDu)min - (EDu)2, (EDu)min - (EDu)3.......... where 1, 2, 3..... represent the name of all files in the directory.

    Here I am sending the code which is given by my Supervisor and I am required to finalize it. Please complete it if possible.

    use strict; my $SCFDoneLowSoFar = 0.0; # The lowest energy found so far my $FileLowSoFar = ''; # The file containing the lowest energy so far foreach my $files (<*log>){ # Loop over all of the files my $E=`grep "SCF Done" $files|awk "{print \\\$5}"`; chomp($E); +# Find the energy in this file # Check if the energy in this file is LOWER than the lowest en +ergy so far # If it is, then it is the NEW lowest energy so far # and the file containing is the new FileLowSoFar print "File $files has energy $E and the lowest energy so far +is $SCFDoneLowSoFar\n"; } print "The lowest total energy was $ELowSoFar\n"; print "This was in file $FileLowSoFar\n";

    I ahve been struggling for more tahn a week.