Read from file > process > output to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from file > process > output to file
# 1  
Old 10-05-2008
Read from file > process > output to file

Hi all,

OK, I am totally new to shell scripting as I just started today. All I want from shell scripting is something very basic, and I've been searching for tutorials on "processing files" and I could not find a suitable one for my level.

I want to read two columns from a data file, one raw at a time, use these values as input to some program, then parse the output of that program (output is text) and append important info to another file

I am going insane about this, please help me find a useful tutorial!!!

Thanks
# 2  
Old 10-06-2008
This is a very "first time question" Smilie
The basic concept should be:
Code:
while read col1 col2
do 
  echo $col1 >> output.file
  echo $col2 >> output.file
done < data.file

For solutions you can use the search tab on this forum... or Google for tutorials for your shell.
# 3  
Old 10-06-2008
Thank you so much, that's very helpful!!
# 4  
Old 10-06-2008
Quote:
Originally Posted by danmero
This is a very "first time question" Smilie
The basic concept should be:
Code:
while read col1 col2
do 
  echo $col1 >> output.file
  echo $col2 >> output.file
done < data.file

For solutions you can use the search tab on this forum... or Google for tutorials for your shell.
this is much better, no need to open and close files multiple times

Code:
while read col1 col2
do 
  echo $col1 
  echo $col2 
done < data.file >> output.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process to read a new file entry and execute a command

I need to develop a process/daemon which will constantly monitor a file for new entry and execute a command. for eg, there is a file /var/log/inotify.log When a new entry like below gets appeneded to this file, execute the command as follows. /home/user/public_html/bad.php|CREATE ... (2 Replies)
Discussion started by: anil510
2 Replies

2. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. UNIX for Advanced & Expert Users

Using awk to read a file and process

I am fairly green using awk so I don't have anything started but what I am trying to do is: I have a file called "contacts" and in the file are 3 fields separate by ;. I want to read each line and send an email script. I have the email function working but just need to know how to setup awk to... (8 Replies)
Discussion started by: ziggy6
8 Replies

4. Shell Programming and Scripting

Read file from input and redirect to output file

Hi , i am having an file which contains 5 file_name data, i need to read the file name and will perform certain operation and generate out file names with named as 5 individual file_names for eg: file.txt contains file_name1.txt|hai file_name2.txt|bye file_name3.txt|how... (3 Replies)
Discussion started by: rohit_shinez
3 Replies

5. Shell Programming and Scripting

Perl: How to read text from file and process $variable in that data too.

In the hello.htm have the sentenses: Hello $name How are you? The perl script: $name = "David"; open(HEADER,"hello.htm"); while(<HEADER>) { $html .= $_; } close(HEADER); print "$html";I making something about template. But it can't process the $name variable. (4 Replies)
Discussion started by: natong
4 Replies

6. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

7. Shell Programming and Scripting

How to read the input from a file in background process?

Hi I have a script to run some other scripts automatically. But while running the script it should take the input value from a text file instead of taking from the keyboard. Please find last two lines of the script below. Here ans should be taken from a text file ineerly without displaying this... (1 Reply)
Discussion started by: shirdi
1 Replies

8. Solaris

file open/read/write/close/access by process

Hi want to know what file (descriptor+filename+socket) is being accessed by particular process on solaris. Purpose : while running perf. test, needs to find where is the bottleneck. We are providing concurrnet load for around 1 hr and needs to capture data related to file usage pattern... (1 Reply)
Discussion started by: raxitsheth
1 Replies

9. Programming

read input-process-output

Can you help me ? I want to write a program ,which can open a input file (input.txt) and run as child process ,then write to output file (output.txt)....... char inFile="input.txt"; char outFile="output.txt"; int main(int argc, char **argv) { pid_t pid=1; int no=0; // no. of... (5 Replies)
Discussion started by: cupid1575
5 Replies

10. Shell Programming and Scripting

How to read/process a .gz file, one line at a time?

Hello I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions. I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep... (2 Replies)
Discussion started by: dayscripter
2 Replies
Login or Register to Ask a Question