looping and saving output of each line separately

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looping and saving output of each line separately
# 1  
Old 07-05-2012
looping and saving output of each line separately

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:
for i in 'cat odon'
do echo $i | ./perm $i > $i
cp beta beta.$i

This does not seem to work as I want. I would appreciate your contribution. Thanks

Last edited by methyl; 07-05-2012 at 12:37 PM.. Reason: please use code tags
# 2  
Old 07-05-2012
What's in perm? Does it read from a pipe, or does it take a parameter? In the script as posted, it does both.
# 3  
Old 07-05-2012
perm contains a program that runs automatically if done right. t contains something like itgen -m 500 -r rhs -b beta -n con.
I want each line to pass through perm and send out beta. The next line should be beta1 etc. I have tried it for just one line and it gave me beta
# 4  
Old 07-05-2012
It is impossible to guess what faulty script is intended to do. I repeat:
What's in perm ? Does it read from a pipe, or does it take a parameter?
# 5  
Old 07-05-2012
perm is a file name I just created and it contains a program whichI want each line to be read into. I just tried to pipe each line to perm. It may not be the right approach to take. The content of perm which automatically produce an output beta for one line of the file odon. My challenge here is to do each line automatically instead of having to manually work through each line
# 6  
Old 07-05-2012
Whether it's the right approach or not really depends on what perm does. It might be the right approach. It might not. We literally have no idea.

Until you explain what perm actually does -- the input you feed into it and the output you expect from it -- we can't help you.
# 7  
Old 07-05-2012
I just created a file and named it perm. It is the content of the file that is important because it contains a program we use in research. The program is: itgen -m 500 -r rhs -b beta -n con (I just created the file to save what I need). Its like doing a*b=c, the the program gets the value of b for you automatically. Each line must pass through this program and it will output b which in my case is beta. That means I have a file named rhs and another named con; but itgen -m 500 -r rhs -b beta -n con will run through each of this files by itself so I don't really need to bother about the files. The first line in the file odon (12 1 1) will pass through itgen -m 500 -r rhs -b beta -n con and beta will be automatically produced (I have tried it with just one line and it gave me beta so it works). My challenge is to take the first line and put it in the file I save as perm, produce beta, then repeat it for each line in odon saving beta as beta0, beta1 etc
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Looping through input/output

Hi, I've got a directory of about 6000 txt files that look like this: a b c d e f g h k l m n I need to execute a command on them to combine them and, in the end, have one big file with all the needed columns taken form all the 6000 files. I've got the "combining" program, but my problem... (26 Replies)
Discussion started by: zajtat
26 Replies

2. Shell Programming and Scripting

sed command is saving output as blank file

Hi, I am working on a script where I am adding adding colors to few of the info in the output. Now , after that is done , I see colour codes in log files which I don't want to see.:mad::mad::mad::mad: So , I tried using sed command in script as below which gives me o/p (new.log) as blank file... (7 Replies)
Discussion started by: Dream4649
7 Replies

3. Shell Programming and Scripting

Saving files with file name as output

Hi, i need help with a file creation of an output program. I've got a program that with #find creates an output for each files in a directory. If i give this command : -o spec$(date -u +%Y%m%dt%H%M) it creates just one file, overwriting all the others since it is the creation date .... (2 Replies)
Discussion started by: Board27
2 Replies

4. Shell Programming and Scripting

Looping over output of 'ls'

Hi, I have some output from 'ls' command and I want to loop over the output in a bash script. What would be a good way to go about it? For example, if the output of the ls command gives me 'prefix1 prefix2 prefix3', how can I set a loop that will iterate over these? many thanks! (5 Replies)
Discussion started by: pc2001
5 Replies

5. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

6. Shell Programming and Scripting

Need some Help for file filteration and saving the output in other directory

Hi all........ Plss do help me.......in a big trouble... :wall::wall::wall: I have 3 directories named as :1. /home/shuchi/source 2./home/shuchi/destination 3./home/shuchi/filter now the problem is /home/shuchi/source has say 2 files with extension .txt as given below : A.txt msisdn ... (5 Replies)
Discussion started by: ektubbe
5 Replies

7. Shell Programming and Scripting

saving output from bash into a file

I am ssh to many servers to get some information... however sometimes the server is unreacheable and i am getting an error. I want to save that output to a file but I am not able to do so... I want to be able to save output of bash into a file.. so when I run this command on a script ssh... (5 Replies)
Discussion started by: eponcedeleonc
5 Replies

8. UNIX for Dummies Questions & Answers

Saving a temporary output within a script

Good morning everyone, i am looking to know how to save the output of a command and reuse it again within a script i already tired this one but it didn't work TEMPDIR=/dir1/dir2 My_command> $TEMPDIR/$TEMPFILE rm $TEMPDIR/$TEMPFILE* it keeps saying "cannot write to a... (15 Replies)
Discussion started by: Portabello
15 Replies

9. UNIX for Dummies Questions & Answers

saving command output to a variable

Hello, I have a shell script containing a command string in the following format: command1 | command2 | cut -c9-16 The output from this is a record number (using characters 9-16 of the original output string) e.g. ORD-1234 I wish to save this value to a variable for use in later commands... (4 Replies)
Discussion started by: philjo
4 Replies

10. Shell Programming and Scripting

Saving output from awk into a perl variable

How would I pass awk output to a perl variable? For example, I want to save the value in the 4th column into the variable called test. My best guess is something as follow, but I am sure this isn't correct. $test = system("awk '/NUMBER/{print \$4}' $_"); (8 Replies)
Discussion started by: userix
8 Replies
Login or Register to Ask a Question

Featured Tech Videos