Unix/Linux Go Back    


UNIX for Advanced & Expert Users 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

UNIX for Advanced & Expert Users


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
laxmi131's Unix or Linux Image
laxmi131 laxmi131 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 25 February 2014, 5:27 AM EST
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
laxmi131's Unix or Linux Image
laxmi131 laxmi131 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 25 February 2014, 5:27 AM EST
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
ranjithpr's Unix or Linux Image
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
$ 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 Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
Annihilannic's Unix or Linux Image
Annihilannic Annihilannic is offline Forum Advisor  
 
Join Date: May 2008
Last Activity: 28 October 2009, 7:03 PM EDT
Location: Sydney, Australia
Posts: 1,009
Thanks: 0
Thanked 2 Times in 2 Posts
Cross posted:

https://www.unix.com/shell-programmin...nd-quotes.html
Sponsored Links
    #5  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
laxmi131's Unix or Linux Image
laxmi131 laxmi131 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 25 February 2014, 5:27 AM EST
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
Hey
Thanks a lot its working
Linux
Sponsored Links
    #6  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
laxmi131's Unix or Linux Image
laxmi131 laxmi131 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 25 February 2014, 5:27 AM EST
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
How can we acheive this using "sed" command
Sponsored Links
    #7  
Old Unix and Linux 10-27-2008   -   Original Discussion by laxmi131
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 13 April 2018, 5:31 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,574
Thanks: 178
Thanked 568 Times in 482 Posts


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"

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Concatenate lines between lines starting with a specific pattern s052866 Shell Programming and Scripting 9 10-24-2010 12:09 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



All times are GMT -4. The time now is 01:55 AM.