Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merge multiple lines

Status
Not open for further replies.

praywin

Programmer
Feb 6, 2003
31
IN
Hi,
I have a file like

abc bcdcde def
efg fgh


I want awk to read it and print

abc bcd cde def
efg fgh
i.e. substitute \ with " "

Can anyone help me here?
I tried
awk '{if ($NF=="\\") {$NF= " ";printf("%s",$0);} else {print}}' file
but it is horribly wrong.

Cheers,
Pravin.

 
I also tried a bash solution

while read line
do
echo $line
done < infile

but it gives the output

abc bcdcde def
efg fgh

Any idea?
Cheers,
Pravin.
 
Code:
$NF == &quot;\\&quot; { $NF = &quot;&quot; ; line = line $0 ; next }
{ print line $0 ; line = &quot;&quot; }
 
substr($0,length($0),1) != &quot;\\&quot; {print; next}
{sub(&quot;.$&quot;, &quot; &quot;, $0); printf $0}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top