Home Man
Search
Today's Posts
Register

Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

need to concatenate two lines if the line doesnt end with quotes

Tags
advanced, concatenate, lines

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-27-2008
need to concatenate two lines if the line doesnt end with quotes

Hi

I am getting a source file where the columns are seperated by comma and double Quotes
Eg1 : "AAA","BBB","CCCC"
in the same source file i am also getting few lines where my last columns double quotes are ending in its next line or the next next line

Eg2: "AAA","BBB","CCC
CC"
(or)

"AAA","BBB","CCC
CC
CCC"
I need to concatenate all such lines( shown in Eg2) and make it in to single line (as shown in Eg1)

Can any one please help me in this regard.How can this be acheived through unix

Thanks in advance
# 2  
Old 10-27-2008
Concatenating two lines in to one based on condition

Hi

I am getting a source file where the columns are seperated by comma and double Quotes
Eg1 : "AAA","BBB","CCCC"

in the same source file i am also getting few lines where my last column double quotes are ending in its next line or the next next line

ForEg2: "AAA","BBB","CCC
CC"
(or)

"AAA","BBB","CCC
CC
CCC"
I need to concatenate all such lines(as shown in Eg2) and make it in to single line (as shown in Eg1)

Can any one please help me in this regard.How can this be acheived through unix

Thanks in advance
# 3  
Old 10-27-2008
$ cat file.txt
"AAA","BBB","CCC
CC"
"AAA","BBB","CCC
CC
CCC"
$ awk '{if(substr($0,length)=="\"") print;else printf("%s",$0);}' file.txt
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"
# 4  
Old 10-27-2008
# 5  
Old 10-27-2008
Hey
Thanks a lot its working
# 6  
Old 10-27-2008
How can we acheive this using "sed" command
# 7  
Old 10-27-2008
Code:
root@isau02:/data/tmp/testfeld> cat infile
"AAA","BBB","CCC
CC"
"AAA","BBB","CCC
CC
CCC"
root@isau02:/data/tmp/testfeld> sed -e :a -e '/[^"]$/ { N; s/\n// ;ta}' infile
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep file and print value only if the following line doesnt contain value xxxx mutley2202 UNIX for Dummies Questions & Answers 6 01-08-2015 02:28 PM
Concatenate small line with next line perl script Ophiuchus Shell Programming and Scripting 2 11-10-2013 02:35 AM
Concatenate lines between lines starting with a specific pattern s052866 Shell Programming and Scripting 9 10-24-2010 12:09 PM
Concatenate two lines in one Orbix Shell Programming and Scripting 5 04-29-2010 04:40 PM
Delete all line breakes from File doesnt work Blackbox Shell Programming and Scripting 3 09-22-2009 08:34 PM
sed / awk to concatenate lines until blank line dunstonrocks Shell Programming and Scripting 11 03-30-2009 11:11 PM
Logfile - extracting certain lines to concatenate into 1 line BecTech Shell Programming and Scripting 3 03-30-2009 07:28 PM
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
Need solution concatenate and display 2 lines as 1 with a condition for 2 line ? vithala UNIX for Advanced & Expert Users 1 07-10-2008 01:27 PM
SSH doesnt exit properly from command line frustrated1 Solaris 4 06-16-2005 04:30 PM


All times are GMT -4. The time now is 11:02 PM.

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