ShellScript to Remove Newline in ouput.csv | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

ShellScript to Remove Newline in ouput.csv

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-27-2012
crmsachin crmsachin is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 27 December 2012, 7:21 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ShellScript to Remove Newline in ouput.csv

Hi friends,
I am running one SQL though .sh file and in output I am seeing newline whevnever There is a new line in column.
I WANT TO REMOVE NEWLINE IN OUTPUT FILE.

Present out put in Column:
-------------------------

Code:
Hi
How 
Are 
You.

Required output in Column:
-------------

Code:
Hi How Are You.

Can anybody help me how to resolve this in Shell Script?? Below is my Script:


Code:
ORACLE_HOME=/app/oracle/product/11.1.0/client_1 ; export ORACLE_HOME
PATH=$PATH:/app/oracle/product/11.1.0/client_1/bin ; export PATH
cd /crmapp/crmpm

m=`date +%Y%m%d`

sqlplus -s abcd/efgh@crmdb << EOF

set echo off
set newpage 0
set space 0
set pagesize 0
set linesize 20000
set feed off
set heading on
set trimspool on


spool Direct_Debit_Report_$m.csv

select 'SR_Number'||','||'BANNumber'||','||'Name'||','||'CPR#'||','||'DD_Ref_Num'||','||'MSISDN'||','||'BankName'||','||'Bank_Account_Name'||','||'AccountNumber'||','||'DD_Max_Amount'||','||'DD_Max_Amount_Amend'||','||'DD_StartDate'||','||'SR_Tier-3'||','||'SR_Created'||','||'SR_Status'||','||'SR_SubStatus'||','||'Description' from dual;

select sr.sr_num||','||b.ou_num||','||b.name||','||can.tax_iden_num||','||sr.X_DD_REF_NUM||','||a.duns_num||','||x.X_BANK_NAME||','||x.X_BANK_ACC_NAME||','||x.X_BANK_ACCOUNT_NUM||','||sr.X_DD_MAX_AMT||','||sr.X_DD_MAX_AMT_AMEND||','||sr.X_DD_START_DATE||','||sr.SR_SUB_AREA||','||SR.CREATED||','||sr.SR_STAT_ID||','||sr.sr_sub_stat_id||','||sr.desc_text
from siebel.s_org_ext a,siebel.s_org_ext b,siebel.s_srv_req sr,siebel.s_srv_req_x x,siebel.s_org_ext can 
where a.ROW_ID = SR.CST_OU_ID AND
a.master_ou_id = can.row_id and
sr.row_id = x.par_row_id and
a.par_ou_id = b.row_id and
sr.sr_sub_area in ('Amendment','Cancellation','New') and
trunc(sr.created) >= (sysdate-7);

spool off
quit
EOF

#mailx -m -s "Direct Debit Report" xxx@viva.com.bh,yyy@viva.com.bh,aimakki.c@viva.com.bh,zzz@viva.com.bh  << EOF
#mailx -m -s "Direct Debit Report $m" aaa@viva.com.bh << EOF
mailx -m -s "Direct Debit Report" aaa@viva.com.bh << EOF



Hi,

PFA Direct Debit SR's since yesterday.

Note: If the sheet is blank it indicates that there is no DD SR raised since yesterday.


Thanks & Regards,
CRM Team

$(/usr/bin/uuencode "/crmapp/crmpm/Direct_Debit_Report_$m.csv" Direct_Debit_Report_$m.csv)

EOF

rm /crmapp/crmpm/Direct_Debit_Report_$m.csv


Last edited by Scrutinizer; 12-27-2012 at 07:19 AM.. Reason: code tags; anonimized email addresses
Sponsored Links
    #2  
Old 12-27-2012
Fundix Fundix is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 16 January 2014, 5:23 AM EST
Posts: 71
Thanks: 16
Thanked 11 Times in 11 Posts
file is

Code:
Hi
How
Are 
You.

Awk command :

Code:
#awk '{ printf "%s ", $0 }' file

Result :

Code:
Hi How Are You.

Sponsored Links
    #3  
Old 12-27-2012
chidori chidori is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 3 December 2013, 12:16 PM EST
Posts: 215
Thanks: 51
Thanked 3 Times in 3 Posts
are you looking out for something like this ?


Code:
[root@testbox tmp]# cat file
Hi
How
Are
You.
[root@testbox tmp]# tr -s '\n' ' ' < file
Hi How Are You.

    #4  
Old 12-27-2012
Jotne's Avatar
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 22 August 2014, 7:56 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
Problem with solution in post #2 and #3 is that it does not stop.
If there are more words following, it will be printed on the same line.
So you need some type of record separator.
Sponsored Links
    #5  
Old 12-27-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try also:

Code:
awk '$1=$1' RS= infile

Sponsored Links
Closed 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
remove ] followed by newline in bash locoroco Shell Programming and Scripting 4 12-15-2011 12:44 PM
Create an .csv/excel file using shellscript Navya Shell Programming and Scripting 12 07-15-2011 10:45 AM
remove newline between two string with sed command in unix shellscript jcrshankar Shell Programming and Scripting 4 02-21-2011 05:46 PM
SED: how to remove newline after pattern? nico.ben Shell Programming and Scripting 1 01-02-2009 09:59 PM
how to remove all tabs and newline (\n) pvr_satya Shell Programming and Scripting 2 08-16-2008 02:38 PM



All times are GMT -4. The time now is 10:02 AM.