Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

READ removing white space, destroying fixed length records

Status
Not open for further replies.

tony500

MIS
Mar 20, 2002
19
0
0
US
I have a data file with fixed length records starting with an ID number. I have another file with a list of ID numbers and names. I'm comparing the data file to the list file and removing any record in the data file that doesn't have a match in the list file. When I do this, the READ comand is removing the white space and in effect destroying the fixed length records. Any suggestions how to fix this?


MY SCRIPT:
while read LINE
do
grep "`echo "${LINE}" | cut -f${1} -d ' '`" ${3} > /dev/null
if [ $? -eq 0 ]; then
echo "found some good stuff"
echo $LINE >> goodstuff
else
echo $LINE >> badstuff
fi
printf "%s" $LINE
done

Any suggestions? Please Help!
Tony You can usually find me at
 
Tony:

before your line

while read LINE

try changing field seperator IFS to some unused character. That should preserve the white space. At least it does on my SCO Open Server V box.

Regards,

Ed
 
Hi Tony,
if your file has no white spaces at the end of line you can do like this:
nl -s' ' FirstInFl |&
# This line writes number at begin of line
while read -p LINE
# your comparing
.........
L1=${LINE#*}
# This line erases first from value of parameter
.........
echo "$L1" >> goodstaff
....
echo "$L1" >> badstaff
fi
done

Regards Boris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top