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
Smilie
# 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

|
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
Sed: how to merge two lines moving matched pattern to end of previous line satir Shell Programming and Scripting 3 09-14-2014 01:26 PM
Delete lines that contain a pattern from specific line to the end. jiam912 Shell Programming and Scripting 1 08-25-2014 05:34 AM
Grep lines with numbers greater than 2 digits at the end of the line jimmyf UNIX for Dummies Questions & Answers 1 02-15-2013 02:37 AM
Stripping double quotes from front and end of a line vx04 UNIX for Dummies Questions & Answers 6 09-15-2012 04:31 AM
concatinate all lines from second line to end of line in perl sujit_singh Programming 7 09-28-2011 02:17 AM
Append text to end of line on all lines giles.cardew Shell Programming and Scripting 5 11-26-2010 10:10 AM
Concatenate lines between lines starting with a specific pattern s052866 Shell Programming and Scripting 9 10-24-2010 01:09 PM
Need help line 35: syntax error: unexpected end of file only 34 lines of code BkontheShell718 Shell Programming and Scripting 7 10-14-2010 04:04 PM
Adding lines at end of a line Ernst Shell Programming and Scripting 19 05-17-2010 12:20 PM
sed / awk to concatenate lines until blank line dunstonrocks Shell Programming and Scripting 11 03-31-2009 12:11 AM
Logfile - extracting certain lines to concatenate into 1 line BecTech Shell Programming and Scripting 3 03-30-2009 08:28 PM
Removing end of line to merge multiple lines tink Shell Programming and Scripting 4 10-14-2008 03:28 PM
concatenate and display 2 lines as 1 with a condition for 2 line ? vithala Shell Programming and Scripting 7 07-11-2008 02: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 02:27 PM
check position of end of line for some specific lines senthil_is Shell Programming and Scripting 1 11-09-2007 01:19 AM
All times are GMT -4. The time now is 11:10 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.