This widget could not be displayed.
1845515 Members
2419 Online
110244 Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
New Discussion
This widget could not be displayed.
This widget could not be displayed.

Re: printing

 
SOLVED
Go to solution
SAM_24
Frequent Advisor

printing

Hi,

I want to print following lines

line1
line2
line3

as

line1 line2 line3.

I want to print in a single line instead of three lines.

Any help is appreciated.

Thanks.
Never quit
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: printing

Hi:

I assume the lines reside in a file. Thus:

# cat filename|xargs

If not, then consider:

# echo "line1\nline2\nline3"|xargs

Regards!

...JRF...
Geoff Wild
Honored Contributor
Solution

Re: printing

Create a script with:

#! /bin/sed -nf

H
$ {
x
s/\n//g
p
}



Example (script caled join.sed):

join.sed yourfile



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
john korterman
Honored Contributor

Re: printing

Hi,
if it is just a matter of translating carriage return characters into spaces, tr is fast, e.g.:
# tr "\012" "\040" < linefile

regards,
John K.
it would be nice if you always got a second chance
SAM_24
Frequent Advisor

Re: printing

Geoff,

May I ask why it is not working if I don't use
H and x commands with s/\n//g?

Thanks a lot.
Never quit
Bill Hassell
Honored Contributor

Re: printing

Here's a couple of alternatives:

cat file_name | paste - - -

(use - for each column needed)

pr -3 -t file_name

(in this case, each line is arranged vertically rather than horizontally)


Bill Hassell, sysadmin
Geoff Wild
Honored Contributor

Re: printing

Well...the H means - Append the contents of the pattern space to the hold space.

The x means - Exchange the contents of the pattern and hold spaces.

I don't know sed enough to explain it...

Here's a handy site:

http://www.unixguide.net/unix/sedoneliner.shtml

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.