loop thru a file
Hello,
Need help on the below, I am new to linux and let me know what i am doing wrong: I have to read from a text file, each line has 3 strings with delimiter ':' example: alex:russo:1986 which is maps to Firstname:LastName:DOB i need something like below: while IFS=':' read line do fn=`echo $line ln=`echo $line` dob=`echo $line` echo 'firstname='$fn echo 'lastname='$ln echo 'DOB='$dob done > input.txt my input.txt file looks like below: alex:russo:1985 sam:dixy:1985 ronald:smith:1984 curry:leaves:1987 linex:redhat:1950 Please help |
Quote:
Code:
while IFS=: read fn ln dob http://tldp.org/LDP/abs/html/ |
I will only say that you're doing just about everything wrong. You need to stop and do a good read of the BashGuide or another good scripting reference, because you really need get the basic concepts down.
One problem I see, for example (other than what was mentioned above) lies here: Code:
while IFS=':' read line And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. PS: Useless Use Of Echo! Try var1=$var2 instead. |
Thanks David and TB0ne, as i said I am new to linux and surely love to going thru the BashGuide. TBOne your response did help me under stand how the IFS will work and split the line, so i should be writting some this like
Code:
|
A good linux tutorial
http://rute.2038bug.com/index.html.gz |
That's a good attitude to have. Keep at it and you'll get there in time.
I was worried that I might've across as too harsh in my last post. But to be honest, there are an impressive number of errors in the small bit of code you posted. I didn't even mention that the quoting is all wrong. ;) Now that you've got it working, here's how it should probably look: Code:
#!/bin/bash |
All times are GMT -5. The time now is 06:12 PM. |