Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: scripting - cat breaking line

From: Matus UHLAR - fantomas <uhlar(at)fantomas.sk>
Date: Sun Jun 24 2007 - 06:49:19 EDT


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(at)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. 


-- 
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Received on Sun Jun 24 06:49:38 2007
Do you need help?X

This archive was generated by hypermail 2.1.8 : Sun Jun 24 2007 - 06:50:02 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library