Group Multiple Lines on SINGLE line matching pattern

Hi Guys,

I am trying to format my csv file. When I spool the file using sqlplus the single row output is wrapped on three lines.

Somehow I managed to format that file and finally i am trying to make the multiple line on single line.

The below command is working fine but I need to pass the DBNAME as dynamic variable in shell script ... I tried this but it is not working any help ?

sed ':a;N;/\n\"ORCL \"/!s/\n/ /;ta;P;D' infile.csv

I need to pass the DB name ORCL as dyanamic variable

export DBNAME=ORCL

sed ':a;N;/\n\"$DBNAME \"/!s/\n/ /;ta;P;D' infile.csv
  • but this is not working

---------- Post updated at 09:23 AM ---------- Previous update was at 09:11 AM ----------

i have tried like this also ... not working the output is below

+ sed ':a;N;/\n\"{$DBNAME} \"/!s/\n/ /;ta;P;D' infile.csv

There are umpteen ways to skin a cat ...
The single quotes prevent the expansion of the shell variable - use double quotes instead. You could also write the script incl. the expanded variable to a file, and then have sed execute that.
For me, the best way would be to tell sqlplus NOT to break the lines but print the entire row output to one line.

1 Like

I tried double quotes like below

sed ":a;N;/\n\"$DBNAME \"/!s/\n/ /;ta;P;D" infile

But the script process this code as below

++ sed ':a;N;/\n"
ORCL "/!s/\n/ /;ta;P;D' infile
sed: -e expression #1, char 9: unterminated address regex

Looke like you have a line break in your variable? How is it assigned?