"sed" ignoring last line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "sed" ignoring last line
# 1  
Old 12-13-2012
"sed" ignoring last line

Hi,

I am giving below command script and getting below output. I tried using "sed" which is ignoring 4th line. Can you please help me to get the expected output like below
Code:
Code:
echo "dis clusqmgr(*) cluster(BT.CL.OFSSTAT4) conname qmtype deftype"| runmqsc -e $QMGR|egrep 'CHANNEL|QMTYPE|CLUSQMGR|CONNAME|DEFTYPE'|sed -e 's/CLUSQMGR(/+/g'|sed -e 's/CLUSQMGR(/+/g'|tr -d "\n"|tr "+" "\n"

Getting Output:

Please note QMTYPE(REPOS) is coming down and then again SU* is coming in next line
Code:
SU.QM.EMB70xtx)                CHANNEL(OFSSTAT4.EMB70xtx.Cx)   CLUSTER(SU.CL.OFSSTAT4)                 CONNAME(x0.N9.70.x0(Tx43x))   DEFTYPE(CLUSSDRA) 
QMTYPE(REPOS)
SU.QM.EMB70xtN)                CHANNEL(OFSSTAT4.EMB70xtN.Cx)   CLUSTER(SU.CL.OFSSTAT4)                 CONNAME(x0.N9.70.xx(Tx43N))   DEFTYPE(CLUSSDRB)
 QMTYPE(REPOS)
SU.QM.OFSMMxTx)                CHANNEL(OFSSTAT4.OFSMMxTx.Cx)   CLUSTER(SU.CL.OFSSTAT4)                 CONNAME(x0.x88.T8.9x(Tx43x))   DEFTYPE(CLUSSDRA)
 QMTYPE(NORMAL)
SU.QM.OFSMMxTN)                CHANNEL(OFSSTAT4.OFSMMxTN.Cx)   CLUSTER(SU.CL.OFSSTAT4)                 CONNAME(x0.x88.T8.94(Tx43N))   DEFTYPE(CLUSRCVR)                       
QMTYPE(NORMAL)

Expecting output:

Code:
SU.QM.EMB70xtx,                 OFSSTAT4.EMB70xtx.Cx,    SU.CL.OFSSTAT4,                  x0.N9.70.x0,Tx43x,    CLUSSDRA,                        REPOS,
SU.QM.EMB70xtN,                 OFSSTAT4.EMB70xtN.Cx,    SU.CL.OFSSTAT4,                  x0.N9.70.xx,Tx43N,    CLUSSDRB,                        REPOS,
SU.QM.OFSMMxTx,                 OFSSTAT4.OFSMMxTx.Cx,    SU.CL.OFSSTAT4,                  x0.x88.T8.9x,Tx43x,    CLUSSDRA,                        NORMAL,
SU.QM.OFSMMxTN,                 OFSSTAT4.OFSMMxTN.Cx,    SU.CL.OFSSTAT4,                  x0.x88.T8.94,Tx43N,    CLUSRCVR,                        NORMAL,


Last edited by Scrutinizer; 12-13-2012 at 08:28 AM.. Reason: quote tags -> code tags
# 2  
Old 12-13-2012
Hi

For the input content you specified, try this:

Code:
$ sed 'N;s/\n/ /' file | awk -F'[)(]' '{for(i=1;i<=NF;i+=2)printf "%s,",$i;print"";}'

Guru.
# 3  
Old 12-13-2012
Code:
 
sed -e 's/) CHANNEL(/, /g' -e 's/) CLUSTER(/, /g' -e 's/) CONNAME(/, /g' -e 's/(Tx/,Tx/g' -e 's/)) DEFTYPE(/, /g' -e 's/) QMTYPE(/, /g' -e 's/)/,/g'

# 4  
Old 01-03-2013
Quote:
Originally Posted by guruprasadpr
Hi

For the input content you specified, try this:

Code:
$ sed 'N;s/\n/ /' file | awk -F'[)(]' '{for(i=1;i<=NF;i+=2)printf "%s,",$i;print"";}'

Guru.
@guruprasad:

I tried belwo one and didn't get anyoutput

Code:
echo "dis clusqmgr(*) cluster(BT.CL.OFSSTAT4) conname qmtype deftype"| runmqsc -e $QMGR|egrep 'CHANNEL|QMTYPE|CLUSQMGR|CONNAME|DEFTYPE'|sed 'N;s/\n/ /' file | awk -F'[)(]' '{for(i=1;i<=NF;i+=2)printf "%s,",$i;print"";}'

got below error

Code:
ksh: syntax error: `;' unexpected


Last edited by Scott; 01-03-2013 at 05:58 AM.. Reason: Code tags, not quote tags
# 5  
Old 01-03-2013
I know this is lengthy one Smilie

Code:
# sed -e 's/)/,/g' -e 's/(//g' -e 's/CHANNEL//g' -e 's/CLUSTER//g' -e 's/CONNAME//g' -e 's/DEFTYPE//g' -e 's/QMTYPE//g' -e 's/Tx4
3/,Tx43/g' -e 's/,,/,/g' file

# 6  
Old 01-03-2013
@Sathya: I didn't get anyoutput for below one

Code:
echo "dis clusqmgr(*) cluster(BT.CL.OFSSTAT4) conname qmtype deftype"| runmqsc -e $QMGR|egrep 'CHANNEL|QMTYPE|CLUSQMGR|CONNAME|DEFTYPE'|
sed -e 's/)/,/g' -e 's/(//g' -e 's/CHANNEL//g' -e 's/CLUSTER//g' -e 's/CONNAME//g' -e 's/DEFTYPE//g' -e 's/QMTYPE//g' -e 's/Tx4 3/,Tx43/g' -e 's/,,/,/g'

# 7  
Old 01-03-2013
Given the output file from your first post, try this:
Code:
$ sed 'N;s:\n: :;s:)::g;s: *[A-Z]*(:, :g' file
SU.QM.EMB70xtx, OFSSTAT4.EMB70xtx.Cx, SU.CL.OFSSTAT4, x0.N9.70.x0, Tx43x, CLUSSDRA, REPOS
SU.QM.EMB70xtN, OFSSTAT4.EMB70xtN.Cx, SU.CL.OFSSTAT4, x0.N9.70.xx, Tx43N, CLUSSDRB, REPOS
SU.QM.OFSMMxTx, OFSSTAT4.OFSMMxTx.Cx, SU.CL.OFSSTAT4, x0.x88.T8.9x, Tx43x, CLUSSDRA, NORMAL
SU.QM.OFSMMxTN, OFSSTAT4.OFSMMxTN.Cx, SU.CL.OFSSTAT4, x0.x88.T8.94, Tx43N, CLUSRCVR, NORMAL

It first appends the next line and removes the <newline> char as you seem to have a two line input, then removes closing parentheses, then replaces all blanks followed by upper case chars followed by an opening parenthesis by <comma><space>. Adapt the number of spaces (or replace by <TAB>) if need be.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

3. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

4. Shell Programming and Scripting

Is it possible to use sed to handle the line contains BOTH "AA" and "BB"

if yes, can some expert give an example Lei (2 Replies)
Discussion started by: yanglei_fage
2 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

SED or AWK "append line to the previous line"

Hi, How can I remove the line beak in the following case if the line begin with the special char “;”? TEXT Text;text ;text Text;text;text I want to convert the text to: Text;text;text Text;text;text I have already tried to use... (31 Replies)
Discussion started by: research3
31 Replies

9. Shell Programming and Scripting

"read" command ignoring leading spaces

I have to read a file line by line, change it and then update the file. Problem is, when i read the file, "read" command ignores leading spaces. The file is a script which is indented in many places for clarity. How to i make "read" command read leading spaces as well. (3 Replies)
Discussion started by: vickylife
3 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question