Reading a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a log file
# 8  
Old 08-19-2015
I just want to read energies from them and make a table as I showed in the fomer post.
and I can only classify the energies in those tables if I have file names.
and the file names are different they can only be found by their extensions .out.

Last edited by raymondg; 08-19-2015 at 05:25 PM..
# 9  
Old 08-19-2015
Specifications are difficult thing to write; wild guessing lead me to offer this as a zeroth approximation for the four files in one directory as posted above:
Code:
awk '
BEGIN   {print "Compound\tState\tMethod\tEnergy"}
        {n=split(FILENAME, T, "-")
         printf "%s\t%s\t%s\n", T[1], substr(T[n],1,1)=="t"?"triplet":"singlet", T[2]=="CC"?"CC":"DFT"
        }
' *.out
Compound    State    Method    Energy
CHSiH3    singlet    CC
CHSiH3    triplet    CC
CHSiH3    singlet    DFT
CHSiH3    triplet    DFT

By no means I'm in a position to fill in the energy column, as the sample input file you posted has 97 occurrences of the word "energy" in it, and even the "FINAL SINGLE POINT ENERGY" phrase that you try to match in your code snippet comes up with 6 different values in that file.
This User Gave Thanks to RudiC For This Post:
# 10  
Old 08-19-2015
the energy which would needs to be placed there is the "FINAL SINGLE POINT ENERGY" which shows up after the keyword "Hurray" shows up.
I had written a code in mathematica to deal it but shell is so different and I'm mixed up!
# 11  
Old 08-19-2015
Try
Code:
awk '
BEGIN           {print "Compound\tState\tMethod\tEnergy"}
FNR==1          {n=split(FILENAME, T, "-")
                 printf "%s\t%s\t%s\t", T[1], substr(T[n],1,1)=="t"?"triplet":"singlet", T[2]=="CC"?"CC":"DFT"
                 FOUND=0
                }
/HURRAY/        {FOUND=1
                }
FOUND &&
/^FINAL.*ERGY/  {print $NF
                }
' *.out
Compound    State    Method    Energy
/tmp/input    singlet    DFT    -39.022584378179

And - try to be way more specific, precise, and detailed in your requests to follow!
This User Gave Thanks to RudiC For This Post:
# 12  
Old 08-20-2015
Quote:
Originally Posted by RudiC
Try
Code:
awk '
BEGIN           {print "Compound\tState\tMethod\tEnergy"}
FNR==1          {n=split(FILENAME, T, "-")
                 printf "%s\t%s\t%s\t", T[1], substr(T[n],1,1)=="t"?"triplet":"singlet", T[2]=="CC"?"CC":"DFT"
                 FOUND=0
                }
/HURRAY/        {FOUND=1
                }
FOUND &&
/^FINAL.*ERGY/  {print $NF
                }
' *.out
Compound    State    Method    Energy
/tmp/input    singlet    DFT    -39.022584378179

And - try to be way more specific, precise, and detailed in your requests to follow!
Sorry I get a syntax error on the line
Code:
printf "%s\t%s\t%s\t", T[1], substr(T[n],1,1)=="t"?"triplet":"singlet", T[2]=="CC"?"CC":"DFT"

Code:
awk: syntax error at source line 4
 context is
	                 printf "%s\t%s\t%s\n", T[1], >>>  substr(T[n],1,1)== <<< 
awk: illegal statement at source line 4
awk: illegal statement at source line 4


Last edited by raymondg; 08-20-2015 at 10:29 AM..
# 13  
Old 08-20-2015
Use nawk on Solaris.
This User Gave Thanks to Corona688 For This Post:
# 14  
Old 08-20-2015
I'm on a max OS X 10.10
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

5. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

6. Shell Programming and Scripting

Menu / Log files - reading / display

So I'm pretty green still at this, and right now I don't even have the IF statements in just trying to get this part to work. I want to basically click optino 1,2,3,4 for which logs I want to search, and then be able to put in the variable I want to grep out? Sounds easy just not clear in my mind... (4 Replies)
Discussion started by: xgringo
4 Replies

7. Shell Programming and Scripting

Reading/Compressing of log file

Hello All Posted a similar thread in some other section too. Regrets if this section is not suitable for this post. Request all the members to be tolerant as i'm a newbie here :) Coming to the topic : I've this huge log files of size 20GB-30 GB in my unix server. I want to analyse the log... (2 Replies)
Discussion started by: sgbhat
2 Replies

8. UNIX for Dummies Questions & Answers

Log File Writing and Reading

Hi all, I have the following shell script code which tries to sftp and writes the log into the log file. TestConnection () { echo 'Connection to ' $DESTUSERNAME@$DESTHOSTNAME $SETDEBUG if ]; then rm $SCRIPT ; fi touch $SCRIPT echo "cd" $REMOTEDIR >> $SCRIPT echo "quit" >>... (10 Replies)
Discussion started by: valluvan
10 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question