Operating System - HP-UX
1838633 Members
1976 Online
110128 Solutions
New Discussion

Re: Appending a string to every line in text file

 
SOLVED
Go to solution
Seah Hee Chuan
Occasional Advisor

Appending a string to every line in text file

Hi

I had created a file abc with `ls > abc `.

I need to append a known string eg "zzzzzzz" to the end of everyline .
Is it possible.
5 REPLIES 5
Thierry Poels_1
Honored Contributor
Solution

Re: Appending a string to every line in text file

hi,

ls | sed "s/$/zzzzzz/" > abc

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Ranjith_5
Honored Contributor

Re: Appending a string to every line in text file


Hi Chuan,

You can do the following also:-

#vi abc

inside vi,

:se nu
:1,Xs/$/zzzzzz/g


where 'X' is the last line number
and 'zzzzzzz' is the word to be appended.

regards,
Syam
Nguyen Anh Tien
Honored Contributor

Re: Appending a string to every line in text file

using substitution of vi
#vi abc
(change vi mode to command mode) by press ESC, Shift+(;) then type
:1,$:s/^/xxxxxxx


(see attache docs for more detail)
HP is simple
Nguyen Anh Tien
Honored Contributor

Re: Appending a string to every line in text file

using substitution of vi
#vi abc
(change vi mode to command mode) by press ESC, Shift+(;) then type
:1,$:s/^/xxxxxxx


(see attache docs for more detail)
HP is simple
Seah Hee Chuan
Occasional Advisor

Re: Appending a string to every line in text file

I use the following to solve my problem

sed '1,Xs/$/zzz/' abc > newfile

where X is the number of lines in the abc