Concatenate two lines in one


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-29-2010
Concatenate two lines in one

Does anyone know a way I can fix my file below where it has lines that are cut?

Just like the (notice the space before ms,c=PH)..

Code:
dn: cn=english,ou=Messaging,ou=lang,o=subject,t=j
 ms,c=PH

which should be
Code:
dn: cn=english,ou=Messaging,ou=lang,o=subject,t=jms,c=PH


The whole text file goes like...

Code:
dn: cn=english,ou=Messaging,ou=lang,o=subject,t=j
 ms,c=PH
objectClass: top
objectClass: javaContainer
objectClass: javaObject
objectClass: javaNamingReference
javaReferenceAddress: #name#subject.lang.Messaging.eng
 lish
javaReferenceAddress: #1#versionID#4.0.1

Sorry for my english!
# 2  
Old 04-29-2010
A solution with AWK :
Code:
awk '
/^ / { line = line substr($0, 2) ; next }
{ if (NR>1) print line; line = $0 };
END { print line }
' inputfile

Jean-Pierre.
# 3  
Old 04-29-2010
this should do the job
Code:
sed -e :a -e '$!N;s/\n //;ta' -e 'P;D' infile

Code:
$ cat infile
dn: cn=english,ou=Messaging,ou=lang,o=subject,t=j
 ms,c=PH
objectClass: top
objectClass: javaContainer
objectClass: javaObject
objectClass: javaNamingReference
javaReferenceAddress: #name#subject.lang.Messaging.eng
 lish
javaReferenceAddress: #1#versionID#4.0.1

$ sed -e :a -e '$!N;s/\n //;ta' -e 'P;D' infile
dn: cn=english,ou=Messaging,ou=lang,o=subject,t=jms,c=PH
objectClass: top
objectClass: javaContainer
objectClass: javaObject
objectClass: javaNamingReference
javaReferenceAddress: #name#subject.lang.Messaging.english
javaReferenceAddress: #1#versionID#4.0.1

# 4  
Old 04-29-2010
OMG! Both works! I'm so happy! Hahaha! Thanks frans and aigles!!!!
# 5  
Old 04-29-2010
Quote:
Originally Posted by Orbix
OMG! Both works! I'm so happy! Hahaha! Thanks frans and aigles!!!!
I had to google to find the meaning of 'OMG'. I think it's not "Object Management Group" Smilie.
# 6  
Old 04-29-2010
Another way with AWK :
Code:
awk -v RS="\0" '{ gsub(/\n /,""); print }' inputfile

Jean-Pierre.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Concatenate three lines into one FredAtArrow UNIX for Dummies Questions & Answers 7 08-14-2014 04:03 PM
Concatenate select lines from multiple files pathunkathunk Shell Programming and Scripting 3 04-13-2014 11:25 AM
How to concatenate lines with specific pattern? nixtime Shell Programming and Scripting 8 06-25-2013 05:39 PM
Concatenate lines with unique string AND number pioavi Shell Programming and Scripting 2 01-18-2012 06:43 AM
Concatenate lines in file shell script systemoper UNIX for Advanced & Expert Users 3 01-14-2012 05:40 PM
Need to concatenate spuriously separated lines lemele Shell Programming and Scripting 16 12-28-2011 01:21 AM
Concatenate two lines in a fIle uday.sena.m Programming 3 09-21-2011 11:50 PM
Concatenate lines between lines starting with a specific pattern s052866 Shell Programming and Scripting 9 10-24-2010 12:09 PM
Concatenate multiple lines based. indrajit_u Shell Programming and Scripting 8 06-30-2010 05:50 PM
concatenate lines in pairs kerl Shell Programming and Scripting 5 06-17-2010 11:26 AM
concatenate lines using shell scripting dtdt Shell Programming and Scripting 13 09-07-2009 12:14 AM
concatenate log file lines up to timestamp AlanC Shell Programming and Scripting 4 06-29-2009 11:38 AM
Concatenate lines in a single paragraph cgkmal Shell Programming and Scripting 4 05-17-2009 01:02 AM
How to concatenate consecutive lines shivi707 UNIX Desktop Questions & Answers 1 01-12-2009 08:08 AM
concatenate and display 2 lines as 1 with a condition for 2 line ? vithala Shell Programming and Scripting 7 07-11-2008 01:01 AM