how do i join two lines from a input file

HI all,
i have a input file,i have to join 2nd line into firstline and 4th line into 2nd line and so on..
for this we also consider odd no. of line.It's operate on original input file but output file should temp file.
like ..
filename=cdr.cfg

line1
line2
line3
line4

Desired output should be like this...
filename=temp.cfg

line1line2
line3line4

If odd no. of lines are in file,then output should be like this..

line1line2
line3

Thnaks
surya

Hi,

Try this:

$ perl -pE 's/\n// if ($. % 2);' infile

Regards,
Birei

Try this,

paste  -d '' - -  < inputfile

Request you to use code tags icon to wrap your input/output files for better readability.

awk '{r=$0;print v=getline? r $0:r}' inputfile > outfile

use the paste command
as paste 1st filename 2nd filename

$ ruby -ne 'print ($.% 2==0)?$_ : $_.chomp!' file 
line1line2 
line3line4  
sed 'N;s/\n//'

Don't think that works if the file has an odd number of lines.

$ cat file
1
2
3
4
5

$ sed 'N;s/\n//' file
12
34

But a slight change:

$ sed '$!N;s/\n//' file
12
34
5

Hi Scottn,
it worked on my computer,

 
echo "1
2
3
4
5" |sed 'N;s/\n//'
12
34
5

Also, I think you are right if the code would be more robust after adding "$!", thanks!

For me not:

echo "1
2
3
4
5" |sed 'N;s/\n//'
12
34

I will try them on Solaris, and whichever works is the one to go with - it doesn't get any more basic than that :slight_smile:

edit:
OK, the results are in :smiley:

# uname -a
SunOS sol10 5.10 Generic_141445-09 i86pc i386 i86pc
# sed 'N;s/\n//' file
12
34
# sed '$!N;s/\n//' file
12
34
5