How to print the words in the same line

Red hat Red hat enterprise linux ws - st...
February 18, 2010 at 18:42:28
Specs: Linux i686

HI,

How to print the words in the same line ( or predefined line ie first line or second line) with a space in a text file ?


cat test

abc def

can we add the new word to the same line

cat >> test

ghi

then the output is

cat test

abc def
ghi

the needed output is

cat test

abc def ghi # 'ghi' should come to the first line

Thanks in advance


See More: How to print the words in the same line

Report •

#1
February 18, 2010 at 21:40:22
This sed command appends 'ghi' to the end of the line:

sed '1s/$/ ghi/' text.fil

The sed command cotains a range factor. the "1" ensures only the first line is acted on. Without the "1", every line is appended.


Report •
Related Solutions


Ask Question