Group Multiple Lines on SINGLE line matching pattern

Tags
file formating, linux scripting, sed, shell scripts

 
Thread Tools Search this Thread
# 1  
Old 05-03-2018
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 ?

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

I need to pass the DB name ORCL as dyanamic variable

Code:
export DBNAME=ORCL

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

- but this is not working


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!


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

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


Last edited by RudiC; 05-03-2018 at 05:25 AM.. Reason: Added CODE tags.
# 2  
Old 05-03-2018
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.
This User Gave Thanks to RudiC For This Post:
RJSKR28 (05-03-2018)
# 3  
Old 05-03-2018
I tried double quotes like below
Code:
sed ":a;N;/\n\"$DBNAME \"/!s/\n/ /;ta;P;D" infile

But the script process this code as below


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

Moderator's Comments:
Mod Comment Please use CODE (nit ICODE) tags as required by forum rules!

Last edited by RudiC; 05-03-2018 at 05:44 AM.. Reason: Changed ICODE to CODE tags.
# 4  
Old 05-03-2018
Looke like you have a line break in your variable? How is it assigned?

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

More UNIX and Linux Forum Topics You Might Find Helpful
Multiple lines to single line kaushik02018 UNIX for Beginners Questions & Answers 4 07-27-2017 02:11 PM
Match Pattern and print pattern and multiple lines into one line tigerhills Shell Programming and Scripting 4 01-11-2015 10:26 AM
Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern essem Shell Programming and Scripting 11 06-05-2014 05:59 AM
Multiple pattern match and print the output in a single line rpm120 Shell Programming and Scripting 4 10-18-2013 09:00 AM
sed command to grep multiple pattern present in single line and delete that line vivek d r Shell Programming and Scripting 14 05-14-2013 09:07 AM
Creating single pattern for matching multiple files. Little Shell Programming and Scripting 2 04-18-2013 02:12 AM
Split single file into multiple files using pattern matching prasadm Shell Programming and Scripting 3 07-19-2012 11:40 PM
Multiple pattern matching using awk and getting count of lines aemunathan Shell Programming and Scripting 6 04-17-2012 09:50 PM
print range of lines matching pattern and previous line siriche Shell Programming and Scripting 1 02-09-2012 09:00 PM
Multiple lines in a single column to be merged as a single line for a record Bhuvaneswari Shell Programming and Scripting 1 08-11-2011 04:16 AM
Merge a group of lines into single line prasanth_babu UNIX for Advanced & Expert Users 8 10-18-2010 02:01 PM
Multiple lines into a single line RickyC9999 Shell Programming and Scripting 4 02-22-2010 03:41 PM
pattern matching over multiple lines and deleting the first Yorkie99 Shell Programming and Scripting 7 11-06-2009 01:56 AM
sort group of n lines base on pattern in first line manishma71 UNIX for Dummies Questions & Answers 1 06-10-2009 08:35 AM
make multiple line containing a pattern into single line VTAWKVT Shell Programming and Scripting 13 12-04-2008 06:40 PM