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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reformating File 2

Status
Not open for further replies.

longs

Programmer
Jul 27, 2007
31
US
Hi All
I am trying to reformat a flat file but im facing a issue
let me explain myself

Orignal File:
010800650022000003190000000+000002ECLPSE BIG E SPEAR000022505 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
010800650012546310530000000+000003DENTYNE ICE GUM 000022005 ^M
010800650012546310510000000+000001DENTYNE ICE GUM 000022005 ^M
010800650034000003470000000+000006YORK MINT TIN 000012405 ^M


but when i run a reformat script im losing all the spaces, which i need;
script is as following:

cat file | while read line
do
echo "20084\c" >> newFile.dat
echo $line >> newFile.dat

done


20084010800650022000003190000000+000002ECLPSE BIG E SPEAR000022505 ^M
20084010800650034000003470000000+000006YORK MINT TIN 000012405 ^M
20084010800650012546310530000000+000003DENTYNE ICE GUM 000022005 ^M
20084010800650012546310510000000+000001DENTYNE ICE GUM 000022005 ^M
20084010800650034000003470000000+000006YORK MINT TIN 000012405 ^M

I have tried it with print as well but no luck so far.
I would like to keep the format as the original file.

Thanks for your help in advance

Laters
 
im losing all the spaces
Replace this:
echo $line >> newFile.dat
with this:
echo "$line" >> newFile.dat

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks allot
Perfectly working!!!
 
You might do better with sed. Try
Code:
sed 's/^/20084/' < file >newFile.dat
This 'replaces' the start of every line (^) with 20084.

On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top