Chemist Needs Help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Chemist Needs Help
# 22  
Old 10-25-2008
Quote:
Originally Posted by jim mcnamara
{printf("%.1f %s %s %s\n", cnt, $0, col3, col4);

One more comma after col3. I must have done that but I can't see how. It works here.
hmmm. Sorry.

Great its coming together. The 3rd and 4th column are not being printed. Any ideas, thanks.
# 23  
Old 10-25-2008
Yes. Those come from this:
Code:
awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out | read col3

This just reads the first 'Done' line from the file. YOu need run this
Code:
awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out

and see what you get. I suspect you get nothing. In that case, play with this line awk statment until it produces what you want. Duplicate your efforts on the other line that creates col4. Dont forget to add the | read col3 and read | col4 statements back onto the line.

If you know what the values are supposed to be anyway, hardcode them in, skip the awk for now example:
Code:
col3=99999
#awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out | read col3

The leading # character comments out the line. Repeat this for the col4 line.
# 24  
Old 10-25-2008
Quote:
Originally Posted by jim mcnamara
Yes. Those come from this:
Code:
awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out | read col3

This just reads the first 'Done' line from the file. YOu need run this
Code:
awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out

and see what you get. I suspect you get nothing. In that case, play with this line awk statment until it produces what you want. Duplicate your efforts on the other line that creates col4. Dont forget to add the | read col3 and read | col4 statements back onto the line.

If you know what the values are supposed to be anyway, hardcode them in, skip the awk for now example:
Code:
col3=99999
#awk '/Done/ {print $2; exit}' Ar_b3lyp_pv5z.out | read col3

The leading # character comments out the line. Repeat this for the col4 line.

It seems when I run the awk '/Done/ {print $5; exit}' Ar_b3lyp_pv5z.out in the command line I do get my one value that I want to repeat 101 times. But when I run the entire script everything is printed except for columns 3 and 4.

Any thoughts. Thanks.

Also I don't know if you care or not but this is technically not my work but yours so I should cite your name as a reference. That's up to you.
# 25  
Old 10-25-2008
I actually have enough publications - I'm not in academe anymore. Thank you, though.

Change both of the awk-s to use column five ( $5 or $6 or $12 or whatever works) and post your code. You did test the "second" awk to see if it gives you data as well in the col4 variable, right?

If you need to get this thing out the door in finite time consider attaching some real files to your post (with dummy data if the data is restricted BUT the correct format is REALLY REALLY important). Why? I didn't know about the $5 thing til now.
What I need is a short sample of expected output, and a few lines from the three input files. I did not ask earlier because people often have restrictions on data samples posted on public forums. Wisely so.
# 26  
Old 10-25-2008
I believe that i attached 3 .out files. The one ArCl.... has 101 points. The other two files Cl... and Ar... have only one point each and those I need repeated in the columns.

Lenny

printf "%s\n%s\n%s\n%s\n" "comment" "x y x" "101" "4 7" > newfile
awk '/Done/ {print $5; exit}' Ar_b3lyp_pv5z.out | read col3
awk '/Done/ {print $5; exit}' Cl_b3lyp_pv5z.out | read col4
awk '/Done/ {print $5}' ArCl_b3lyp_pv5z.out | \
awk -v col4="$col4" -v col3="$col3" ' BEGIN { cnt =1.5 }
{printf("%.1f %s %s %s\n", cnt, $0, col3, col4); cnt+=.1 }'>> newfile

~

Last edited by gingburg; 10-25-2008 at 09:06 PM..
# 27  
Old 10-27-2008
I was also wondering if some of the information like the file names, numbers after the $, and newfile name can be made variables that will prompt you from the command line.

Thank you,
Lenny
# 28  
Old 10-27-2008
Code:
#!/bin/sh
# FILE: chem.awk  requires execute permission
# usage: ./chem.awk infile infile2 infile3 outfile

# where parms are:
#   $1 = infile1  $2 = infile2   $3 = infile3  $4 = outfile
# do not forget to change "comment" to something menaingful if needed
echo "
parameters
$1
$2
$3
$4"


# start the FILE
printf "%s\n%s\n%s\n%s\n" "comment" "x y x" "101" "4 7" > ./newfile

# read in two constants
awk '/Done/ {print $5; exit}' "$1" | read col3
awk '/Done/ {print $5; exit}' "$2" | read col4

# loop thru the big input FILE writing 101 rows
awk '/Done/ {print $5}' "$3" | \
awk -v col4="$col4" -v col3="$col3" ' BEGIN { cnt =1.5 }
              {printf("%.1f %s %s %s\n", cnt, $0, col3, col4) 
              cnt+=.1 }'>> ./newfile
# rename the output FILE to what was required
mv ./newfile "$4"            
echo "lines in outputfile: $(wc -l "$4") created"
exit 0
# EOF: chem.awk

sample run:
Quote:
csadev:/home/jmcnama> chmod +x chem.awk
csadev:/home/jmcnama> chem.awk Ar_b3lyp.in Cl_b3lyp.out ArCl_b3lyp.out testoutfile

parameters
Ar_b3lyp.in
Cl_b3lyp.out
ArCl_b3lyp.out
testoutfile
lines in outputfile: 105 testoutfile created
contents of testoutfile:
Code:
comment
x y x
101
4 7
1.5 -987.240232155 -527.566333244 -460.316564467
1.6 -987.378613978 -527.566333244 -460.316564467
1.7 -987.487844944 -527.566333244 -460.316564467
1.8 -987.576209346 -527.566333244 -460.316564467
1.9 -987.648115849 -527.566333244 -460.316564467
2.0 -987.705862095 -527.566333244 -460.316564467
2.1 -987.751166930 -527.566333244 -460.316564467
2.2 -987.785959917 -527.566333244 -460.316564467
2.3 -987.812247576 -527.566333244 -460.316564467
2.4 -987.831921303 -527.566333244 -460.316564467
2.5 -987.846536754 -527.566333244 -460.316564467
2.6 -987.857308288 -527.566333244 -460.316564467
2.7 -987.865185276 -527.566333244 -460.316564467
2.8 -987.870904590 -527.566333244 -460.316564467
2.9 -987.875028391 -527.566333244 -460.316564467
3.0 -987.877975343 -527.566333244 -460.316564467
3.1 -987.880062544 -527.566333244 -460.316564467
3.2 -987.881523538 -527.566333244 -460.316564467
3.3 -987.882526772 -527.566333244 -460.316564467
3.4 -987.883205057 -527.566333244 -460.316564467
3.5 -987.883655405 -527.566333244 -460.316564467
3.6 -987.883934862 -527.566333244 -460.316564467
3.7 -987.884085930 -527.566333244 -460.316564467
3.8 -987.884156857 -527.566333244 -460.316564467
3.9 -987.884181120 -527.566333244 -460.316564467
4.0 -987.884165804 -527.566333244 -460.316564467
4.1 -987.884118398 -527.566333244 -460.316564467
4.2 -987.884055803 -527.566333244 -460.316564467
4.3 -987.883991158 -527.566333244 -460.316564467
4.4 -987.883924918 -527.566333244 -460.316564467
4.5 -987.883855232 -527.566333244 -460.316564467
4.6 -987.883784527 -527.566333244 -460.316564467
4.7 -987.883718868 -527.566333244 -460.316564467
4.8 -987.883658530 -527.566333244 -460.316564467
4.9 -987.883601613 -527.566333244 -460.316564467
5.0 -987.883548439 -527.566333244 -460.316564467
5.1 -987.883499264 -527.566333244 -460.316564467
5.2 -987.883455190 -527.566333244 -460.316564467
5.3 -987.883415341 -527.566333244 -460.316564467
5.4 -987.883378082 -527.566333244 -460.316564467
5.5 -987.883343308 -527.566333244 -460.316564467
5.6 -987.883311536 -527.566333244 -460.316564467
5.7 -987.883283425 -527.566333244 -460.316564467
5.8 -987.883258813 -527.566333244 -460.316564467
5.9 -987.883235960 -527.566333244 -460.316564467
6.0 -987.883213988 -527.566333244 -460.316564467
6.1 -987.883193153 -527.566333244 -460.316564467
6.2 -987.883173892 -527.566333244 -460.316564467
6.3 -987.883156467 -527.566333244 -460.316564467
6.4 -987.883141143 -527.566333244 -460.316564467
6.5 -987.883127703 -527.566333244 -460.316564467
6.6 -987.883115029 -527.566333244 -460.316564467
6.7 -987.883102516 -527.566333244 -460.316564467
6.8 -987.883090229 -527.566333244 -460.316564467
6.9 -987.883078556 -527.566333244 -460.316564467
7.0 -987.883067832 -527.566333244 -460.316564467
7.1 -987.883058250 -527.566333244 -460.316564467
7.2 -987.883049895 -527.566333244 -460.316564467
7.3 -987.883042444 -527.566333244 -460.316564467
7.4 -987.883035500 -527.566333244 -460.316564467
7.5 -987.883028833 -527.566333244 -460.316564467
7.6 -987.883022252 -527.566333244 -460.316564467
7.7 -987.883015730 -527.566333244 -460.316564467
7.8 -987.883009380 -527.566333244 -460.316564467
7.9 -987.883003396 -527.566333244 -460.316564467
8.0 -987.882997987 -527.566333244 -460.316564467
8.1 -987.882993214 -527.566333244 -460.316564467
8.2 -987.882988946 -527.566333244 -460.316564467
8.3 -987.882985074 -527.566333244 -460.316564467
8.4 -987.882981482 -527.566333244 -460.316564467
8.5 -987.882978055 -527.566333244 -460.316564467
8.6 -987.882974716 -527.566333244 -460.316564467
8.7 -987.882971411 -527.566333244 -460.316564467
8.8 -987.882968124 -527.566333244 -460.316564467
8.9 -987.882964890 -527.566333244 -460.316564467
9.0 -987.882961789 -527.566333244 -460.316564467
9.1 -987.882958870 -527.566333244 -460.316564467
9.2 -987.882956162 -527.566333244 -460.316564467
9.3 -987.882953681 -527.566333244 -460.316564467
9.4 -987.882951415 -527.566333244 -460.316564467
9.5 -987.882949340 -527.566333244 -460.316564467
9.6 -987.882947423 -527.566333244 -460.316564467
9.7 -987.882945624 -527.566333244 -460.316564467
9.8 -987.882943900 -527.566333244 -460.316564467
9.9 -987.882942219 -527.566333244 -460.316564467
10.0 -987.882940565 -527.566333244 -460.316564467
10.1 -987.882938937 -527.566333244 -460.316564467
10.2 -987.882937332 -527.566333244 -460.316564467
10.3 -987.882935754 -527.566333244 -460.316564467
10.4 -987.882934216 -527.566333244 -460.316564467
10.5 -987.882932741 -527.566333244 -460.316564467
10.6 -987.882931344 -527.566333244 -460.316564467
10.7 -987.882930032 -527.566333244 -460.316564467
10.8 -987.882928802 -527.566333244 -460.316564467
10.9 -987.882927649 -527.566333244 -460.316564467
11.0 -987.882926572 -527.566333244 -460.316564467
11.1 -987.882925570 -527.566333244 -460.316564467
11.2 -987.882924639 -527.566333244 -460.316564467
11.3 -987.882923771 -527.566333244 -460.316564467
11.4 -987.882922956 -527.566333244 -460.316564467
11.5 -987.882922180 -527.566333244 -460.316564467

 
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Chemist Needs Help part II

Hello friends, I was wondering if you can help me with probably a simple function to you all: the sample looks and has this format. I was wondering how I could extract the first and second column starting including the line 'E/N and Ko' and not stop until there are no more lines. Thank you for... (5 Replies)
Discussion started by: gingburg
5 Replies
Login or Register to Ask a Question