Chemist Needs Help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Chemist Needs Help
# 1  
Old 10-23-2008
Chemist Needs Help

Hello All I am a chemist and really dont know too much about programming but here goes.

Essentially I need to create a script that I can run which will do the following.
Create a file where the first four lines are a set of commands that are the same for all the files. E.g
ln1: comment
ln2: x y x
ln3: 101
ln4: 4 7

So the script should print those line into a new file first.

Then i need to make 4 columns.
The first I need to be 1.5 +0.1 100 times.
e.g.
1.5
1.6
1.7
1.8
1.9
etc.

The second column I need to be a column of data which I have used the command awk '/Done/ {print $2}' file
There will be 101 numbers extracted
Note: I would like Done and the number to be a variable to input in the command line.

The third and fourth are the same as the second except there will only be one point that I need to repeat 101 times.

If someone could help me that would be amazing. Also if someone is an expert I will pay them via paypal to help me occasionally. Thank you Lenny.

Last edited by gingburg; 10-23-2008 at 03:54 PM..
# 2  
Old 10-23-2008
Well, you're short on exact information, so my attempt is generalized. It also isn't all that efficient. I picked 42 and 69.42 as the two fixed numbers.
Code:
printf "%s\n%s\n%s\n%s\n" "comment" "x y x"  "101"  "4 7" > newfile

awk '/Done/ {print $2}'  file | \
 awk ' BEGIN { cnt =1.5 }
         {printf("%.1f  %s  42 69.42\n", cnt  $0); cnt+=.1 } >> newfile

# 3  
Old 10-23-2008
Exact Info

Quote:
Originally Posted by jim mcnamara
Well, you're short on exact information, so my attempt is generalized. It also isn't all that efficient. I picked 42 and 69.42 as the two fixed numbers.
Code:
printf "%s\n%s\n%s\n%s\n" "comment" "x y x"  "101"  "4 7" > newfile

awk '/Done/ {print $2}'  file | \
 awk ' BEGIN { cnt =1.5 }
         {printf("%.1f  %s  42 69.42\n", cnt  $0); cnt+=.1 } >> newfile


Where can I specify with better information
# 4  
Old 10-23-2008
Jim, the first part is perfect. I will try to explain the columns a little better.

I need 4 columns:

The first should be 1.5 through 11.5 by 0.1 increments.

The second column will have 101 15-digit numbers which I have previously extracted with the awk command. The first 15-digit number should be in the same row as 1.5

The third column will have one 15 digit number that I will use the same awk function to retrieve with as i did before. But since I only have one number i need to repeat it 101. The same goes for the fourth.

In the end i should have 4 columns:

1.5 (15-digit number) (15-digit number) (15-digit number)
1.6 (15-digit number) (15-digit number) (15-digit number)

note thr last two columns will have the same 15 digit numbers going down the columns but each column will not have the same number.

Thanks, hope that helps.
# 5  
Old 10-23-2008
The code above will work for you - plugin correct values for the red text below:
Code:
printf "%s\n%s\n%s\n%s\n" "comment" "x y x"  "101"  "4 7" > newfile

awk '/Done/ {print $2}'  file | \
 awk ' BEGIN { cnt =1.5 }
         {printf("%.1f  %s  42 69.42\n", cnt  $0); cnt+=.1 } >> newfile

Keep all quotes and punctuation characters as they are. They have meaning. Just use alphanumerics and . for a decimals and +- for signs on numbers if needed. File names cannot contain spaces or weird characters.

The number of rows you create in the output file is totally depdendent on the number of rows you read in via the first awk statement. ie., the number of lines read in from "file". Nothing is doing any counting for you. If you don't get 101 lines look to your input data.
# 6  
Old 10-23-2008
Quote:
Originally Posted by jim mcnamara
The code above will work for you - plugin correct values for the red text below:
Code:
printf "%s\n%s\n%s\n%s\n" "comment" "x y x"  "101"  "4 7" > newfile

awk '/Done/ {print $2}'  file | \
 awk ' BEGIN { cnt =1.5 }
         {printf("%.1f  %s  42 69.42\n", cnt  $0); cnt+=.1 } >> newfile

Keep all quotes and punctuation characters as they are. They have meaning. Just use alphanumerics and . for a decimals and +- for signs on numbers if needed. File names cannot contain spaces or weird characters.

The number of rows you create in the output file is totally depdendent on the number of rows you read in via the first awk statement. ie., the number of lines read in from "file". Nothing is doing any counting for you. If you don't get 101 lines look to your input data.
Okay everything seems good but the values 42 and 69.42 also need to be extraced using the same awk command how do I put that command in there. Lenny
# 7  
Old 10-23-2008
Are the values for the now-dummy 42 and 69.42 column also in the same file we are using to drive input?
 
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