Shell script to csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to csv
# 1  
Old 03-15-2012
Shell script to csv

I am preparing script and trying to send output into CSV format. there is property called RNAME when it is blank, next propery(XMIT) is coming into RNAME propery. So i want whenever RNAME is blank it should put "," in that field. So that all will fit in proper coloums in csv file. Can you please let me know how to put this "," when there is a blank space.

PFB code:
Code:
do
rq=$queue
lq=`echo "dis qr($queue) rname"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep RNAME| cut -d '(' -f2| cut -d ')' -f1`
rqm=`echo "dis qr($queue) rqmname"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep RQMNAME| cut -d '(' -f2| cut -d ')' -f1`
xmitq=`echo "dis qr($queue) xmitq"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep XMITQ| cut -d '(' -f2| cut -d ')' -f1`
chl=`echo "dis chl(*) xmitq"| runmqsc $QMGR |egrep 'CHANNEL|XMITQ'|egrep -v 'CLUSSDR|CLUSRCVR|RCVR|SYSTEM|SVRCONN'|sed s/'CHA
NNEL'/+/g|tr -d '\n'|tr '+' '\n'|grep $xmitq|awk '{print $1}'| sed -e 's/(/ /' -e 's/)/ /'`
ip=`echo "dis chl($chl) conname"|runmqsc $QMGR | tr ' ' '\n' | sed 's/*^//'| grep CONNAME| cut -d '(' -f2`
echo $rq $lq $xmitq $rqm $chl $ip| awk '{print $1 "," $2 "," $3 "," $4 "," $5 "," $6 }'
done


Last edited by Scott; 05-23-2012 at 11:19 AM.. Reason: Restored question
# 2  
Old 03-15-2012
I'm not exactly sure what your are trying to do.
But I think you can simply put the "," in the "echo" itself instead of piping it to awk.

Code:
echo $rq, $lq, $xmitq, $rqm, $chl, $ip

# 3  
Old 03-15-2012
Hi,

I prepared script and i am sending output put to csv file which is excel. So whenever lq property is blank next field xmitq is coming into lq property. So what i want is whenever lq is blank it should print ",". That is why i am using "," in awk. So it will separate the value and keep it in next coloumn. CSV(Comma separated value)

Last edited by darling; 03-15-2012 at 12:23 PM..
# 4  
Old 03-15-2012
Please show the input you have and the output you want. There's undoubtedly more efficient ways than 7 lines of cut and grep in backticks.
# 5  
Old 03-15-2012
See the output. First one is proper.
Quote:
CT.MSSA26T1.NPIC.HUB_TO_NPIC_APO.01
CT.PR.MSSA26T1.NPIC.HUB_TO_NPIC_APO.01
CT.XM.ASSA10T1_MSSA26T1.B1
CT.QM.MSSA26T1
ASSA10T1.MSSA26T1.B1
10.81.31.3
but second one expecting as
Quote:
CT.QM.ASSA46T1
, (Here it is blank, so i want here ",")
CT.XM.ASSA10T1_ASSA46T1.D1
CT.QM.ASSA46T1
ASSA10T1.ASSA46T1.D1
101.181.131.139

Last edited by darling; 03-15-2012 at 12:32 PM..
# 6  
Old 03-15-2012
I mean the outputs from "dis qr($queue) rname" and the like.

Without seeing the actual input you have, I will have no idea why this code isn't (or even is) producing the output you want. I don't have the equivalent commands installed to experiment with to hope and understand your actual purpose in this program.
# 7  
Old 03-15-2012
PFB my full script

Quote:
#!/bin/ksh
QMGR=$1
echo "Displaying Remote queue information\n"
echo "\nQUEUE,RNAME,XMITQ,RQMNAME,CHANNEL,IPADDRESS"
echo "dis qr(*)" |runmqsc $QMGR| grep QUEUE| grep -v SYSTEM| cut -d '(' -f2| cut -d ')' -f1| while read queue
do
rq=$queue
lq=`echo "dis qr($queue) rname"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep RNAME| cut -d '(' -f2| cut -d ')' -f1`
rqm=`echo "dis qr($queue) rqmname"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep RQMNAME| cut -d '(' -f2| cut -d ')' -f1`
xmitq=`echo "dis qr($queue) xmitq"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep XMITQ| cut -d '(' -f2| cut -d ')' -f1`
chl=`echo "dis chl(*) xmitq"| runmqsc $QMGR |egrep 'CHANNEL|XMITQ'|egrep -v 'CLUSSDR|CLUSRCVR|RCVR|SYSTEM|SVRCONN'|sed s/'CHA
NNEL'/+/g|tr -d '\n'|tr '+' '\n'|grep $xmitq|awk '{print $1}'| sed -e 's/(/ /' -e 's/)/ /'`
ip=`echo "dis chl($chl) conname"|runmqsc $QMGR | tr ' ' '\n' | sed 's/*^//'| grep CONNAME| cut -d '(' -f2`
echo $rq $lq $xmitq $rqm $chl $ip| awk '{print $1 "," $2 "," $3 "," $4 "," $5 "," $6 }'
done
echo "\n"
echo "\nDisplaying Alias Queue Information\n"
echo "ALIAS QUEUE,TARGET QUEUE"
echo "dis qa(*)"| runmqsc $QMGR| grep QUEUE| grep -v SYSTEM| cut -d '(' -f2| cut -d ')' -f1| while read queue
do
qa=$queue
targq=`echo "dis qa($queue) targq"| runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep TARGQ| cut -d '(' -f2| cut -d ')' -f1`
echo $qa $targq| awk '{print $1"," $2}'
done
echo "\n"
echo "\nDisplaying Local queue information\n"
echo "\nLOCAL QUEUE"
echo "dis ql(*) USAGE"|runmqsc $QMGR| grep QUEUE|grep -v SYSTEM| grep -v XMITQ| cut -d '(' -f2 | cut -d ')' -f1
echo "\n\n"
echo "Displaying receiver channel information\n"
echo "CHANNEL,SENDER IPADDRESS"
echo "dis chl(*) chltype(rcvr)"| runmqsc $QMGR |grep CHANNEL|grep -v SYSTEM| cut -d '(' -f2 | cut -d ')' -f1| while read chl
do
ip=`echo "dis chs($chl)"|runmqsc $QMGR| tr ' ' '\n'| sed 's/^*//'| grep CONNAME| cut -d '(' -f2| cut -d ')' -f1`
echo $chl $ip| awk '{print $1","$2}'
done

I will give qmgr as input. I hope now u can understand
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to fetch values in csv

I need to fetch below values from this file. (1 Reply)
Discussion started by: nit42
1 Replies

2. Programming

Shell script - to see if any change from last csv

hi all, i attach a csv file of what im trying to explain basically i get iMacro (like an excel macro that you can record and play back recordings but its for web browsers) to download csv reports of the printer(s) when you open the csv report it contains certain cells - D7 - black... (5 Replies)
Discussion started by: robertkwild
5 Replies

3. Shell Programming and Scripting

CSV File Creation Within Shell Script

Hi All, I am trying to create a CSV file within a shell script test.ksh and the code snippet is something like below: #!/usr/bin/ksh # Set required variables. . $HOME/.prof # Output file path Group1=/tmp/G1.csv Group2=/tmp/G2.csv Group3=/tmp/G3.csv $ORACLE_HOME/bin/sqlplus -s... (2 Replies)
Discussion started by: swasid
2 Replies

4. Shell Programming and Scripting

Reading a csv file using shell script

Hello All, I have a csv file that looks like below ProdId_A,3.3.3,some text,some/text,sometext_1.2.3 ProdId_B,3.3.3,some text,some/text,sometext_1.2.3 ProdId_C,3.3.3,some text,some/text,sometext_1.2.3 ProdId_A,6.6.6,some text,some/text,sometext_9.9.9 I will get ProdId from... (5 Replies)
Discussion started by: anand.shah
5 Replies

5. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

6. Shell Programming and Scripting

Shell script for CSV conversion

thanks for allowing me join your forum i have an output of linux command "who" which provides following details..... CURRENT USER/ACCT INFO 17:31:36 up 4:49, 4 users, load average: 0.03, 0.04, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - 12:59 ?xdm? 4:54 0.02s /bin/sh /usr/bi... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

7. Shell Programming and Scripting

convert this into csv using awk/shell script

Hi Scripting gurus, I need to convert following text snippet into csv. please help Input heading1 = data1 heading2 = data2 .. .. heading n = data n heading 1 = data1 .. .. Output data1,data2,....,data n (3 Replies)
Discussion started by: azs0309
3 Replies

8. UNIX for Advanced & Expert Users

format csv file using shell script

i have a report.csv file from oracle datavase In that file data is like this with report heading and date SALES DAILY REPORT DATE: 06-26-2007 REPORT NAME: SALES DATA AA.BB.CCCC.DDDD,BBBBB,06-26-2007,0,BEGIN,END ZZ.VV.DDDD.XXXXXXX,MMMMMM,06-25-2007,18,BEGIN,END... (3 Replies)
Discussion started by: raosurya
3 Replies

9. Shell Programming and Scripting

Help in parsing a CSV file with Shell script

I have a CSV file which contains number series as one of the fields. Some of the records of the field look like : 079661/3 I have to convert the above series as 079661 079662 079663 and store it as 3 different records. Looking for help on how to achieve this. Am a newbie at Shell... (10 Replies)
Discussion started by: mihirk
10 Replies
Login or Register to Ask a Question