Operating System - Linux
1752810 Members
5808 Online
108789 Solutions
New Discussion юеВ

need help appending lines/combining lines within a file...

 
SOLVED
Go to solution
Manuel Contreras
Regular Advisor

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line?

I have the following file that contains some blank lines and some lines I would like to append to the previous line...

current file:
checking dsk c19t2d6

checking dsk c19t2d7

checking dsk c19t3d0

checking dsk c21t0d4
/dev/dsk/c21t0d4

checking dsk c21t0d5
/dev/dsk/c21t0d5

checking dsk c21t0d6
/dev/dsk/c21t0d6

checking dsk c21t0d7
/dev/dsk/c21t0d7


looking for something like this:

checking dsk c19t2d6
checking dsk c19t2d7
checking dsk c19t3d0
checking dsk c21t0d4 /dev/dsk/c21t0d4
checking dsk c21t0d5/dev/dsk/c21t0d5
checking dsk c21t0d6/dev/dsk/c21t0d6
checking dsk c21t0d7/dev/dsk/c21t0d7

any assistance would be appreciated...thanks and happy new year,
manuel
2 REPLIES 2
Sandman!
Honored Contributor
Solution

Re: need help appending lines/combining lines within a file...

Hello Manuel,

Here is an awk solution that you can use:

# awk 'BEGIN{RS="";FS="\n"} {print $1,$2}' inputfile

cheers!
Manuel Contreras
Regular Advisor

Re: need help appending lines/combining lines within a file...

checking c18t13d5 /dev/dsk/c18t13d5
checking c18t13d6 /dev/dsk/c18t13d6
checking c18t13d7 /dev/dsk/c18t13d7
checking c18t14d0 /dev/dsk/c18t14d0
checking c18t14d1 /dev/dsk/c18t14d1
checking c18t14d2 /dev/dsk/c18t14d2
checking c18t14d3 /dev/dsk/c18t14d3
checking c18t14d4 /dev/dsk/c18t14d4
checking c18t14d5 /dev/dsk/c18t14d5
checking c18t14d6 /dev/dsk/c18t14d6
checking c18t14d7 /dev/dsk/c18t14d7
checking c18t15d0 /dev/dsk/c18t15d0
checking c18t15d1 /dev/dsk/c18t15d1
checking c18t15d2 /dev/dsk/c18t15d2
checking c18t15d3 /dev/dsk/c18t15d3
checking c18t15d4 /dev/dsk/c18t15d4
checking c18t15d5 /dev/dsk/c18t15d5
checking c18t15d6
checking c18t15d7
checking c19t0d0
checking c19t0d1
checking c19t0d2
checking c19t0d3
checking c19t0d4

worked like a charm, thanks :D