looping line by line and saving output result on diff files with different names
I have been trying this program for a long time. I am trying to read a file named "odon" line by line; read the first line, send it to do a command saved in a file "perm", once the first line has finished going through the content of the file perm, the result is saved with the number of the line. Once that is done, the script reads the second line and repeats the process until all the lines have been read, sent to the other file and the output saved. This is what I mean:
12 1 1 2 1 1 3 1 1 92 1 1 read line 12 1 1, send it into file "perm" which contains a command, then the output is saved as beta. The next file as beta1, the next file as beta2 etc. The content of perm will output "beta" when it is read in the right way. I used only one 12 1 1 and it gave me beta, but to read each line and save with different names is proving difficult. This is what I have done so far: #!/bin/sh for i in 'cat odon' do echo $i | ./perm $i > $i cp beta beta.$i done This does not seem to work as I want. I would appreciate your contribution. Thanks |
Look into using a while loop.
Code:
while read line ; do |
It does not save beta for each of the lines on a separate file. It only gives one file named beta
|
So how come you are using a separate bash script for one command? Could you just do this?
Code:
i=0 |
its is not creating different files. I am trying to get a different beta for each line when it passes through perm. what are f1 and -d
|
That was just an example. The code I put in my last post will output different beta files (beta0, beta1, beta2...etc) with the first number before a space in the file "odon". I was unsure of why you were sending the data to a different script instead of just putting it all in this one. What I typed up was just an example of cutting the first number.
According to my script, it will take the input of odon: 12 1 1 2 1 1 3 1 1 92 1 1 And output into beta0: 12 output to beta1: 2 output to beta2: 3 etc... |
Hello
I think that's you're looking for: Code:
i=0; while read line; do echo "$line" >> "beta$i";((i++));done <odon |
[quote]
what are f1 and -d [/code] http://linux.die.net/man/1/cut See also http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
All times are GMT -5. The time now is 11:34 PM. |