Re: scripting - cat breaking line
On 23.06.07 14:23, L.V.Gandhi wrote:
> Subject: scripting - cat breaking line
> I have a file temp1 as below
> lvgandhi@lvgvaio:~/stock$ cat temp1
> ABB,ABB LTD., 4730.00, 4779.00, 4700.00, 4726.45,59655
> ACC,ACC LIMITED, 860.00, 864.90, 844.30, 852.25
> ,228318
> When I run on command line as
> lvgandhi@lvgvaio:~/stock$ for line in $(cat temp1);do echo
> "20070622,$line">>temp2 ;done
it's not "cat" who is breaking lines. This script will fetch content of
"temp1" file to the script, and bash splits fields by any whitespace
charactes, including spaces and tabs, so the "echo" command is calles for
every "word" in a file and echo puts newline at the end of output line by
default.
> I get temp2 as
> lvgandhi@lvgvaio:~/stock$ cat temp2
> 20070622,ABB,ABB
> line is breaking at every space.
> How to avoid this?
either change IFS only to contain newline, or forget using $(cat ...) and
use different cycle:
while read line
do
echo "20070622,$line"
done < temp1 > temp2
(or >>temp2 if you want to append to the "temp2" file)
--
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Eagles may soar, but weasels don't get sucked into jet engines.
Reply to: