Hi All,
I have a script like this which read a file and take data with file seperator ,
and it is working fine for only one line.If i am giving two line of data in this file it is taking the second line only.Can anyone help me to solve the problem.My aim is to read the file each line by line.
The file entry is something like
10.99.7.110,KBL18031,/dir1,/dir2
10.99.6.154,KBL02012,/dir1/dir2
script is like this ....
while read inputline
do
ATMIP="$(echo $inputline |cut -d, -f1)"
ATMNAME="$(echo $inputline |cut -d, -f2)"
ATMDIR1="$(echo $inputline |cut -d, -f3)"
ATMDIR2="$(echo $inputline |cut -d, -f4)"
done < testdetails.conf
jaduks
June 8, 2008, 12:16am
2
Definitely the 2nd line entries(or last line entries) of each variable (ATMIP,ATMNAME,ATMDIR1,ATMDIR2) will be present as values in the respective variables as per your code.
Do you want to print all the values for each of the variables you are extracting using cut ? If you could provide your expected o/p, would be a great help for all to answer.
//Jadu
renjesh:
while read inputline
do
ATMIP="$(echo $inputline |cut -d, -f1)"
ATMNAME="$(echo $inputline |cut -d, -f2)"
ATMDIR1="$(echo $inputline |cut -d, -f3)"
ATMDIR2="$(echo $inputline |cut -d, -f4)"
done < testdetails.conf
... #do something
If you process after the loop, that's normal to be only the last line. Try to process in loop.
while read inputline
do
ATMIP="$(echo $inputline |cut -d, -f1)"
ATMNAME="$(echo $inputline |cut -d, -f2)"
ATMDIR1="$(echo $inputline |cut -d, -f3)"
ATMDIR2="$(echo $inputline |cut -d, -f4)"
... #do something
done < testdetails.conf
My file contains 131 entries(ATMIP,ATMNAME,/DIR./DIR ) and i want all the values instead of just last value
I am using the values for FTPing and fetching some files from the ATM.
it is something like this.......
ftp -n -v -i >> $ERRFILE 2>&1 << cmd
open $ATMIP
cd $ATMDIR1
get $FILENAME_A
cd ..
cd $ATMDIR2
cd $DATEDIR
mget $FILENAME_B
bye
cmd
jaduks:
Definitely the 2nd line entries(or last line entries) of each variable (ATMIP,ATMNAME,ATMDIR1,ATMDIR2) will be present as values in the respective variables as per your code.
Do you want to print all the values for each of the variables you are extracting using cut ? If you could provide your expected o/p, would be a great help for all to answer.
//Jadu
yes I want all the values............
As "danmero" stated above, you should do your print(or any) operation inside the while loop(not outside).
A different look of the same:
$ awk 'BEGIN{FS=","}{print "ATMIP="$1"\nATMNAME="$2"\nATMDIR1="$3"\nATMDIR2="$4}' testdetails.conf
or
$ awk 'BEGIN{FS=",";OFS="\n"}{print "ATMIP="$1,"ATMNAME="$2,"ATMDIR1="$3,"ATMDIR2="$4}' testdetails.conf
//Jadu