The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help to process each line in a file... shyjuezy UNIX for Dummies Questions & Answers 7 05-14-2008 04:20 AM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 10:15 AM
Multiple file processing - 1st line only to process - search/match substring toneatlondon Shell Programming and Scripting 2 01-02-2008 05:20 PM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-20-2007 09:29 PM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 11:36 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2005
Registered User
 

Join Date: Jul 2004
Posts: 31
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-23-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
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
Reply With Quote
  #3 (permalink)  
Old 05-25-2005
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 109
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
Reply With Quote
  #4 (permalink)  
Old 05-25-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
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.
Reply With Quote
  #5 (permalink)  
Old 05-25-2005
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 109
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
Reply With Quote
  #6 (permalink)  
Old 05-25-2005
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 109
Perderabo said :

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

ans it works !

Thanks all
Chris
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0