Output to single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output to single line
# 15  
Old 03-17-2012
@Darling,

are you able to solve this problem ? i saw your PM regarding this post..
# 16  
Old 03-18-2012
Still i am facing the issue...
# 17  
Old 03-19-2012
If you don't get what you expect with :

Code:
echo "dis ql(*) CLUSTER"|runmqsc -e CT.QM.CNEDCT1 | nawk '/CLUSTER/{c=$NF}/QUEUE/{print $NF", "c}{next}' RS=')' FS='('

This may be because the output sample you provided is not sufficient, you can then just
Code:
 echo "dis ql(*) CLUSTER"|runmqsc -e CT.QM.CNEDCT1 >output.txt

Then upload your output.txt on this forum and let us know what final result you expect so we can give a try on a real example.
# 18  
Old 03-19-2012
Hi,

I have attached the output file. I am expecting below output.
Queue, Cluster (If there is no value of cluster then it should display blank should be followed comma",")
1st condition: it should print before _TO and after TO_
2nd condition: if there is no "TO" in queue, it should display last 3rd and 4th value separated by ","
Code:
CT.CL.AIBGTCT2.GTC.AIB_TO_GTC_MB_MNSD_REQ.01, CT.CL.AIBGTCT2, AIB, GTC
ABC,
CT.CL.GTCIRMT2.GTC.IRAMS_TO_GTCJ_MA_MODB_RES.01, CT.CL.GTCIRMT2, IRAMS, GTC
CT.CL.SBLGTCT1.GTC.MDT_REQUEST.01, GTC, MDT

Thanks In Advance

Last edited by Scott; 03-19-2012 at 05:22 PM.. Reason: CODE TAGS
# 19  
Old 03-19-2012
Next time, for those who takes the time to read you and to understand your problem, please, provide all requirements at once in your first post.

Code:
$ cat myawk
/CLUSTER/{c=$NF}
/QUEUE/{if(length(c)<2) {print $NF OFS;next}
x=$NF
t=(x~/_TO_/)?1:0
r="^[^_]+"
match(x,r)
n=split(substr(x,RTSART,RLENGTH+1),a,"\.")
p=t?a[n] OFS a[n-1]:a[n-1] OFS a[n]
print $NF OFS c OFS p;delete a;x=c=t=p=z
}{next}

Code:
$ echo "dis ql(*) CLUSTER" | runmqsc -e CT.QM.CNEDCT1 | awk -f myawk RS=')' FS='(' OFS=','
ABC,
CT.CL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,MRS,GTC
CT.CL.GTCSIMT1.GTC.SIM_TO_GTC_MODB_21CN_REQ.01,CT.CL.GTCSIMT1,SIM,GTC
CT.CL.GTCSPCT2.GTC.SPC_TO_GTCJ_MORT_REQ.01,CT.CL.GTCSPCT2,SPC,GTC
CT.CL.GTCSPCT2.GTC.SPC_TO_GTCJ_TEST_REQ.01,CT.CL.GTCSPCT2,SPC,GTC
CT.CL.GTCSPCT4.GTC.SPC_TO_GTCJ_MORT_REQ.01,CT.CL.GTCSPCT4,SPC,GTC
CT.CL.GTCSPCT4.GTC.SPC_TO_GTCJ_TEST_REQ.01,CT.CL.GTCSPCT4,SPC,GTC
CT.CL.SBLGTCT1.GTC.MDT_REQUEST.01,CT.CL.SBLGTCT1,GTC,MDT
CT.PR.CNEDCT1.GTC.MODB_T2R_GTC.01,
CT.PR.CNEDCT1.GTC.MORT_REQ.01,
CT.PR.CNEDCT1.GTC.RAMBO_TO_GTC_MODB_REQ.01,
CT.PR.CNEDCT1.GTC.TEST_REQ.01,
CT.PR.CNEDCT1.SIMPLE_TO_GTC_MODB_REQ.01,
CT.PR.TARGET,
CT.PR.TEMP.01,
CT.XM.CNEDCT1_SPACET2.D1,


Last edited by ctsgnb; 03-19-2012 at 06:32 PM.. Reason: Code fix in red
# 20  
Old 03-20-2012
Another one to try:

Code:
echo "dis ql(*) CLUSTER" | runmqsc -e CT.QM.CNEDCT1 |
awk -F'[)(]' '
/CLUSTER/{
  if(!/QUEUE/)getline p
  $0=$0p
  s=$4 OFS $2
  m=split($4,T,"[._]")
  if($4~/TO/){
    for(i=1;i<=m;i++)if(T[i]=="TO")s=s OFS T[i-1] OFS T[i+1]
  }
  else if($4~/_/)s=s OFS T[m-3] OFS T[m-2]
  print s
}' OFS=", "


Code:
ABC,  
CT.CL.AIBGTCT2.GTC.AIB_TO_GTC_MB_MNSD_REQ.01, CT.CL.AIBGTCT2, AIB, GTC
CT.CL.B2BGTCT1.GTC.B2B_TO_GTCJO_MNSD_MB_RES.01, CT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CL.GTCSPCT2.GTC.SPC_TO_GTCJ_MORT_REQ.01, CT.CL.GTCSPCT2, SPC, GTCJ
CT.CL.GTCSPCT2.GTC.SPC_TO_GTCJ_TEST_REQ.01, CT.CL.GTCSPCT2, SPC, GTCJ
CT.CL.GTCSPCT4.GTC.SPC_TO_GTCJ_MORT_REQ.01, CT.CL.GTCSPCT4, SPC, GTCJ
CT.CL.GTCSPCT4.GTC.SPC_TO_GTCJ_TEST_REQ.01, CT.CL.GTCSPCT4, SPC, GTCJ
CT.CL.SBLGTCT1.GTC.MDT_REQUEST.01, CT.CL.SBLGTCT1, GTC, MDT
CT.PR.CNEDCT1.GTC.MODB_T2R_GTC.01,  , MODB, T2R
CT.PR.CNEDCT1.GTC.MORT_REQ.01,  , GTC, MORT
CT.PR.CNEDCT1.GTC.RAMBO_TO_GTC_MODB_REQ.01,  , RAMBO, GTC
CT.PR.CNEDCT1.GTC.TEST_REQ.01,  , GTC, TEST
CT.PR.CNEDCT1.SIMPLE_TO_GTC_MODB_REQ.01,  , SIMPLE, GTC
CT.PR.TARGET,  
CT.PR.TEMP.01,  
CT.XM.CNEDCT1_SPACET2.D1,  , XM, CNEDCT1

---------- Post updated 20-03-12 at 06:08 ---------- Previous update was 19-03-12 at 21:19 ----------

Your original requirements would have required:
Code:
echo "dis ql(*) CLUSTER" | runmqsc -e CT.QM.CNEDCT1 |
awk -F')|(' '/CLUSTER/{if(!/QUEUE/)getline p;$0=$0p;print $4,$2}' OFS=", "

# 21  
Old 03-30-2012
Hi,

can you please explain what exactly below command does.. it seems it is little tricky

Quote:
nawk -F'[)(]' '
/CLUSTER/{
if(!/QUEUE/)getline p
$0=$0p
s=$4 OFS $2
m=split($4,T,"[._]")
if($4~/TO/){
for(i=1;i<=m;i++)if(T[i]=="TO")s=s OFS T[i-1] OFS T[i+1]
}
else if($4~/_/)s=s OFS T[m-3] OFS T[m-2]
print s
}'

Last edited by darling; 03-30-2012 at 10:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

2. Shell Programming and Scripting

convert single line output to multiple line

Hi all, I have a single line output like below echo $ips 10.26.208.28 10.26.208.26 10.26.208.27 want to convert above single line output as below format. Pls advice how to do ? 10.26.208.28 10.26.208.26 10.26.208.27 Regards Kannan (6 Replies)
Discussion started by: kamauv234
6 Replies

3. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

4. Shell Programming and Scripting

Merge multi-line output into a single line

Hello I did do a search and the past threads doesn't really solve my issue. (using various awk commands) I need to combine the output from java -version into 1 line, but I am having difficulties. When you exec java -version, you get: java version "1.5.0_06" Java(TM) 2 Runtime... (5 Replies)
Discussion started by: flagman5
5 Replies

5. Shell Programming and Scripting

Output to be in single line

Hi All, Small script but :wall:, please help in this regard. for i in 1 2 3 do echo $i done result : 1 2 3 I want the above to be printed as below expected result: 1 2 3 Thanks in advance :) (3 Replies)
Discussion started by: girish_satyam
3 Replies

6. Shell Programming and Scripting

Output coming in different line instead of single line

Hi Guys, I have an oracle database, I am trying to query the database and route it to file. But the records instead of coming in a single line, are coming in three lines. Can you please help me.. in this.. sqlplus -s $SRMUserid/$SRMPassword@$SRMServer<< EOF >log.out; select * from... (5 Replies)
Discussion started by: mac4rfree
5 Replies

7. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

8. AIX

ls command output in single line

Hi, Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)? I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands? Thanks for your help Sheshadri (7 Replies)
Discussion started by: arsheshadri
7 Replies

9. Shell Programming and Scripting

Multi-line output to single line

Hello, How can I take the following output: outputa outputb outputc and turn it into single line ouput, with a single space between each field like below: outputa outputb outputc (7 Replies)
Discussion started by: LinuxRacr
7 Replies

10. Shell Programming and Scripting

Need output in different lines not in one single line

I am getting the coutput like this as show below in one single line, where as the command is executed is several lines and the output should also be requied in several lines, not in one single line. Anyone any idea? p4 opened -a | grep *locked* | awk '{ printf $8 }' >/tmp/aa $ cat... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question