Concatenate two lines in one

Tags
shell scripts

Login 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 to Reply

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

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

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?