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

<b>A quick teaser with tr</b>

Status
Not open for further replies.

smithia6

Technical User
Aug 28, 2002
35
US
Hi,

Maybe it cannot be done but I would like any help I am offered.

I have text appending to a text file like the example below.

text1 text2 text3 text4 etc....

What I would like to do is run a script to change the white spaces so the text in the text file would look like this..

text1\ntext2\ntext3\ntext4\n etc....

When I use Unix utilities the \n means new line so how can I change or append the text to a file in this format??

Regards
Ian


 
Hi
Try this
for i in `cat textfile`
do
echo -n $i"\n" >> newfile
done
 
Hi Mrregan

This is the command I ran

for i in `cat tmp1`
do
echo -n $i"\n" > tmp2
done

This was the 1st file contents.
text1 text2 text3 text4

This is what it did.
-n text4

What I need is
text1\ntext2\ntext3\ntext4

It was worth a try anyway thanks... have you got any more ideas ????

Regards
Ian
 
hi,
You forgot the double >> characters. This works fine for me. I cant see how you could possibly get a "-n" instead of a "\n" .
 
Hi,
Do a man on your echo command. The -n option on my machine suppress newline characters. If yours cant, you may have to use a tr command on the resulting file to strip the newline characters.
 
A working variation of sed 's/ /\\n/g' should not
be hard to come by.
 
Bingo.

Well done that did it.

Regards
Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top