LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk command and loops (https://www.linuxquestions.org/questions/linux-newbie-8/awk-command-and-loops-4175470897/)

Uzer 07-25-2013 12:07 PM

awk command and loops
 
Hello,
I am dealing with the following problem: I am using a software for physics calculations and I use as input for this program a certain .txt file (which I open with emacs). The file contains a series of numbers put in columns. I want to change the element which is found in the 2nd row and in the second column by 0,001 and save this file under the name ("POS") in order to run again the program with "POS" as input file. I want to do this action for 100 steps and it is very tiring to do by hand....
What can I do in the terminal to command this algorithm? so far i found foreach and awk command helpful but i don't know how to use them.
Thank you in advance

David the H. 07-25-2013 12:20 PM

Sorry, but your text description really isn't detailed enough. Could you please post a short example of the input text (or a reasonable facsimile) and the desired output you want from it?

Also be sure to tell us if there's anything unusual about your environment, such as if you're on a non-linux system.

sryzdn 07-25-2013 12:26 PM

Quote:

Originally Posted by Uzer (Post 4996638)
Hello,
I am dealing with the following problem: I am using a software for physics calculations

what's the name of the physics code?

Firerat 07-25-2013 01:36 PM

Quote:

Originally Posted by Uzer (Post 4996638)
Hello,
I am dealing with the following problem: I am using a software for physics calculations and I use as input for this program a certain .txt file (which I open with emacs). The file contains a series of numbers put in columns. I want to change the element which is found in the 2nd row and in the second column by 0,001 and save this file under the name ("POS") in order to run again the program with "POS" as input file. I want to do this action for 100 steps and it is very tiring to do by hand....
What can I do in the terminal to command this algorithm? so far i found foreach and awk command helpful but i don't know how to use them.
Thank you in advance

I'm Sorry but I don't understand what you want/need.

I'm going to try a break it up a little

Let Input be input.txt
Let Output be POS-001.txt
LoopStart
from Input
send line 1 to Output
Line 2 , field 2 .. add (or subtract?) 0.001 ( assuming , was typo )
send new line 2 to POS.txt
send rest of lines to POS.txt

for further 99 times
Let Input be Output
Let Output be Output+1 ( POS-002.txt )

Repeat Loop


It would help greatly if you provide a sample Input and Output ( 1 and 2 ) ( say 10 lines, or 11 including header )
Do you only want to operate on Line2 ( assuming line 1 is header ), or All Lines


All times are GMT -5. The time now is 06:04 AM.