Process file line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process file line by line
# 1  
Old 05-23-2005
Process file line by line

Hi

I have a csv file as follows

608, Barnwood PFS,,2
150, Barnwood CS,2,4
etc

When i do for lines in `cat file.dat` the space in second argument seems to screwing the lines up.

Any suggestions to get around this?

Thanks
# 2  
Old 05-23-2005
The slow for-loop and the useless use of cat can all be avoided with....
Code:
while read line; do
  # do whatever you want to ${line} - let's just echo it
  echo "${line}"
done < inputfile.csv

Cheers
ZB
# 3  
Old 05-25-2005
Hi ,

i encountered the following problem doing that :

while read line
do
serveur1=`echo $line|awk 'BEGIN {FS="\/"} {print $1}'`
serveur2=`echo $line|awk 'BEGIN {FS="\/"} {print $1}'|sed -e s/A/B/g`
chemin1=`echo $line|awk 'BEGIN {FS="\ "} {print "/base/base01/"$2}'`
chemin2=`echo $line|awk 'BEGIN {FS="\ "} {print "/base/base01/"$2}'|sed -e s/base01/base02/g`

rsh $serveur1 -l notes01 "mv $chemin1 $chemin1.leon"

done < $fic_tmp1


the while treatment doesn't treat correctly the input file and exit after the first line.
It seems that the differents variables in the rsh command don't return correctly the hand to the while treatment !

How to correct that ?

Thanks in advance
Christian
# 4  
Old 05-25-2005
You have to use field separator as ",". what you are going to from
608, Barnwood PFS,,2
150, Barnwood CS,2,4

please elaborate to help you out.

hth.
# 5  
Old 05-25-2005
If i suppress the "rsh" statement and simply do "echo $line" , the loop is working correctly so what's the matter with rsh command ?

Christian
# 6  
Old 05-25-2005
Perderabo said :

"Your rsh should have a -n option. Use it."

ans it works !

Thanks all
Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

2. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Help to process line by line and assign value to variables

Hi, there I have a file with tab and space as field separator. I need to assign values to variables then work with them, line by line. The code I wrote only works when each line has only one word. It doesn't work for the current situation. for line in `cat file.txt`; do ID=`awk '{print... (4 Replies)
Discussion started by: cwzkevin
4 Replies

5. Shell Programming and Scripting

How to process log file line by line?

Greetings, I'm new to this forum, also new to shell script I have done some simple shell script before, like backup linux machine using rsync and crontab, but now I need to do some log analyzing, which is beyond my ability... so I'm going to seek for help in this forum, hope someone could give... (5 Replies)
Discussion started by: lunaticdawn
5 Replies

6. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

7. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

8. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

9. UNIX for Dummies Questions & Answers

shell script to process file line by line

Hi , I am new to shell scripting (ksh shell) and trying to accomplish few requiremtns. I have a file with the following format EMP NO EMP NAME AGE Amt Paid 12 Mark Taylor 32 32333 14 James Brown... (5 Replies)
Discussion started by: royalsing
5 Replies
Login or Register to Ask a Question