On Wed, Jun 13, 2007 at 01:58:18PM -0700, L.V.Gandhi wrote: > I created a .csv file in this format from a original file from the net. The > last field here is the last field in original file also. I made this file as > original file has empty lines and single field lines also. > SYMBOL,HIGH_PRICE,LOW_PRICE,HI_52_WK,LO_52_WK > BHARTIARTL,809.00,790.00,882.05,307.30 > BHEL,1327.00,1301.00,2918.65,1301.00 > I am using this script to find high/low > #!/bin/bash > rm -f highs > rm -f lows > touch lows > for line in $(cat temp.csv) > do > low52=$(echo $line|cut -d, -f5) > high52=$(echo $line|cut -d, -f4) > low=$(echo $line|cut -d, -f3) > high=$(echo $line|cut -d, -f2) > stock=$(echo $line|cut -d, -f1) > if [ $high52 = $high ] > then > echo $stock >> highs > fi > if [ $low52 = $low ] > then > echo $stock >> lows > fi > done > I get highs file. I don't get lows file. I feel there is some unprintable at > the end of csv file. Hence matching fails. > I added one more field and found that ^M in the LO_52_WK field before comma. > I tried sed -e 's/M$//'. this didn't help. > Any solutions? Different tact but have you looked at awk, it handles csv's really well
something like awk '{if ($2 = $4) then print $1 } ' input.csv for the highs and for the lows awk '{if ($3 = $5) then print $1 } ' input.csv ps - haven't done awk for a bit the syntax might be a bit off then there is perl need use Text::CSV; > -- > L.V.Gandhi > http://lvgandhi.tripod.com/ > linux user No.205042
signature.asc
Description: Digital signature