Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Group Multiple Lines on SINGLE line matching pattern

file formating, linux scripting, sed, shell scripts

Login to Reply

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 ?

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

I need to pass the DB name ORCL as dyanamic variable


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

- but this is not working

Moderator's Comments:
Group Multiple Lines on SINGLE line matching pattern 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

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

Last edited by RudiC; 05-03-2018 at 04: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.
The Following User Says Thank You to RudiC For This Useful Post:
RJSKR28 (05-03-2018)
# 3  
Old 05-03-2018
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

Moderator's Comments:
Group Multiple Lines on SINGLE line matching pattern Please use CODE (nit ICODE) tags as required by forum rules!

Last edited by RudiC; 05-03-2018 at 04: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?
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern essem Shell Programming and Scripting 11 06-05-2014 04:59 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 08:07 AM
Creating single pattern for matching multiple files. Little Shell Programming and Scripting 2 04-18-2013 01:12 AM
Split single file into multiple files using pattern matching prasadm Shell Programming and Scripting 3 07-19-2012 10:40 PM
Multiple pattern matching using awk and getting count of lines aemunathan Shell Programming and Scripting 6 04-17-2012 08:50 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 03:16 AM
Merge a group of lines into single line prasanth_babu UNIX for Advanced & Expert Users 8 10-18-2010 01:01 PM
pattern matching over multiple lines and deleting the first Yorkie99 Shell Programming and Scripting 7 11-06-2009 12:56 AM
sort group of n lines base on pattern in first line manishma71 UNIX for Dummies Questions & Answers 1 06-10-2009 07:35 AM
make multiple line containing a pattern into single line VTAWKVT Shell Programming and Scripting 13 12-04-2008 05:40 PM

All times are GMT -4. The time now is 08:18 AM.

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