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


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
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  
$ 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"
# 7  
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 or Register to Reply

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

More UNIX and Linux Forum Topics You Might Find Helpful
Stripping double quotes from front and end of a line
vx04
I have a file and some records may contain double quotes at beginning and at end of line. So how do I strip them? For Example, file is somethings like this Field1;Field2;Field3 01;'Test';'Test Field3' "01;'This is 2nd field';This is 3rd field' " Desired Output is: ...... UNIX for Dummies Questions & Answers
6
UNIX for Dummies Questions & Answers
sed / awk to concatenate lines until blank line
dunstonrocks
Sample input (line feed indicated by ) --------------- The red fox jumped over the brown fence of the red hous He then went into the orchard --------------- Desired Output --------------- The red fox jumped over the brown fence of the red house He then went into the orchard... Shell Programming and Scripting
11
Shell Programming and Scripting
Logfile - extracting certain lines to concatenate into 1 line
BecTech
I've got a log file from automatic diagnostic runs. The log file is appended to each time an automatic log is run. I'd like to just pull certain lines from each run in the log file, and concatenate them into 1 comma delimited line (for export into excel or an html table). Each diagnostic run...... Shell Programming and Scripting
3
Shell Programming and Scripting
concatenate and display 2 lines as 1 with a condition for 2 line ?
vithala
I have 2 pattern of lines (SQL query and Time taken)in a log i need to capture all SQL queries with time taken >20 sec and need to display as one line. 2 lines from log: 2007-10-23 11:39:17,061 DEBUG - SQL Query : SELECT A.GROUP_CD , C.FN_CD FROM UP_GROUP A , PRD_GROUP_TO_FN B , PRD_FN...... Shell Programming and Scripting
7
Shell Programming and Scripting
Need solution concatenate and display 2 lines as 1 with a condition for 2 line ?
vithala
I have 2 pattern of lines (SQL query and Time taken)in a log i need to capture all SQL queries with time taken >20 sec and need to display as one line. 2 lines from log: 2007-10-23 11:39:17,061 DEBUG - SQL Query : SELECT A.GROUP_CD , C.FN_CD FROM UP_GROUP A , PRD_GROUP_TO_FN B , PRD_FN...... UNIX for Advanced & Expert Users
1
UNIX for Advanced & Expert Users