Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Tags
file formating, linux scripting, sed

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-03-2018   -   Original Discussion by RJSKR28
RJSKR28's Unix or Linux Image
RJSKR28 RJSKR28 is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 3 May 2018, 4:36 AM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
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:
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



Code:
+ 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.
Sponsored Links
    #2  
Old Unix and Linux 05-03-2018   -   Original Discussion by RJSKR28
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2018, 3:55 PM EDT
Location: Aachen, Germany
Posts: 12,919
Thanks: 429
Thanked 3,968 Times in 3,649 Posts
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)
Sponsored Links
    #3  
Old Unix and Linux 05-03-2018   -   Original Discussion by RJSKR28
RJSKR28's Unix or Linux Image
RJSKR28 RJSKR28 is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 3 May 2018, 4:36 AM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
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:
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 Unix and Linux 05-03-2018   -   Original Discussion by RJSKR28
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2018, 3:55 PM EDT
Location: Aachen, Germany
Posts: 12,919
Thanks: 429
Thanked 3,968 Times in 3,649 Posts
Looke like you have a line break in your variable? How is it assigned?
Sponsored Links
Reply

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
Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern essem Shell Programming and Scripting 11 06-05-2014 04:59 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 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



All times are GMT -4. The time now is 08:41 PM.