1834811 Members
2099 Online
110070 Solutions
New Discussion

Join lines together

 
Enda martin
Occasional Contributor

Join lines together

Is it possible to concatenate lines together within a file using cat or any other unix command (within vi I use shift + J)

For example :-
1
2
3
4

=>

12
34
5 REPLIES 5
Thierry Poels_1
Honored Contributor

Re: Join lines together

hi,
within vi:

1,$g/./.,.+1j

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

Re: Join lines together

#split -l 1 your_file
#paste xaa xab > test
#paste xac xad >> test
Jerry Jordak
Advisor

Re: Join lines together

If you want a real quick and dirty way, this script should do it:

#!/bin/ksh

while read A
do
read B
echo "$A$B"
done

Pipe the file you want to modify into it and redirect the output to another file. HTH.

-JWJ
Rodney Hills
Honored Contributor

Re: Join lines together

Try the following-
pr -2tas: yourfile | sed -e 's/://'
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: Join lines together

Hi Edna:

Try this:

# awk '{if (NR % 2 == 0) {print X$0} else X=$0} END {print X}' /tmp/yourfile

...JRF...