1751944 Members
4682 Online
108783 Solutions
New Discussion юеВ

Scripting help

 
SOLVED
Go to solution
Paul Thomson_2
Super Advisor

Scripting help

Hi. I have a file which contains data in specific positions, its a CISAM file.
When I cat the file normally for example,

cat file | cut -c 265 returns
Y
Y
Y
N

However, when I
cat file | while read line

The "read line" section truncates the position of 265 and leaves only one space between the text fields.

For example cat file | head -1 shows
AIMPORT 001199910251416U094CLE 199911241809Q823EYX IMPORT AUTO ALLOCATION
GBP
00000000018000
Y A


But with the while read line , $line shows as
AIMPORT 001199910251416U094CLE 199911241809Q823EYX IMPORT AUTO ALLOCATION GBP 00
000000018000 Y A

I am not too sure how to use $IFS.
How can I get "read" to not remove the spaces !!?
Argh ye land lovers !
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripting help

Hi:

You need to use double quotes. Consider:

#!/usr/bin/sh
while read LINE
do
echo "${LINE}"
echo ${LINE}
done < file

...compare the output when you run this.

Note that 'cat file|whle read...' adds a needless process. Let the shell do the work as I show above.

Regards!

...JRF...
Paul Thomson_2
Super Advisor

Re: Scripting help

Thanks James, answered my question !!

Argh ye land lovers !