SUSE Linux iTOps Tube

Monday, May 7, 2012

echo of a string variable is on broken into two lines

Hello, I have a a file delimited by pipes. What I'm doing in the script is first getting a list of all the values in the 11th column. Well, first part(LIST) gets the last field in the 11th column which is delimited by ";". The second part(LIST2), breaks it down again like the first part, by 11th column and then break it down again by ";" and then echo any matches that's associate with the first search. What I'm trying to do is not important. Just trying to figure out why does the script break "L-US LIST" into two different lines when it's one item? I'm thinking that when a variable is stored in the variable(LIST2), if there's more than one value, it's delimited by spaces. So when the for loop goes thru them it interprets L-US LIST as two entities. Is this so?



Here's a sample file:



cat testfile.txt

INDY|SBF|||||N|N|N|TIME|4:L-MAKER;L-US LIST;L-PLAIN;L-INVT|||R|0

INDY|SIRI|||||N|N|N|TIME||||C|0

INDY|SORF|||||N|N|N|TIME|4:L-US LIST;L-PLAIN;L-INVS|||C|0

INDY|STANDARD|||||N|N|N|TIME|4:L-MAKER;L-US LIST;L-PLAIN;L-INVD|||A|0

INDY|SWIB|||||N|N|N|TIME||||F|0

INDY|SWIS|||||N|N|N|TIME||||A|0

INDY|TRUS|||||N|N|N|TIME|4:L-MAKER;L-PLAIN;L-INVD|||K|0

INDY|TUDOR|||||N|N|N|TIME||||C|0

INDY|TURNER|||||N|N|N|TIME|4:L-MAKER;L-US LIST;L-PLAIN;L-INVK|||A|0

INDY|UST|||||N|N|N|TIME|4:L-MAKER;L-PLAIN;L-INVK|||D|0





And here's the script:



cat probscript.sh

#!/bin/bash



sesID="INDY"



DIR="/home/testing/files"

LIST="`grep $sesID $DIR/testfile.txt|awk -F'|' '{print $11}'|cut -d':' -f2|awk -F';' '{print $NF}'`"



for sess in $LIST

do

LIST2="`grep $sesID $DIR/testfile.txt|grep -w "$sess"|awk -F'|' '{print $11}'|cut -d':' -f2|tr ";" "\n"`"



for sess2 in $LIST2



do

if [ $sess != $sess2 ]

then

#print out the sessions

echo "$sess $sess2"

fi

done



done







And here's part of the output, notice that L-US LIST is broken into two:

./probscript.sh

L-INVT L-MAKER

L-INVT L-US

L-INVT LIST

L-INVT L-PLAIN

L-INVS L-US

L-INVS LIST

L-INVS L-PLAIN

L-INVD L-MAKER





Can anybody tell me how to fix this in the variable(LIST2)? Thx for checking.











No comments:

Post a Comment