I know there are quite a few questions asked on this topic. But I need help in a case basis.When i try to put more than 3 pattern in the option, i will get the error like that…
sed: -e expression #1, char 24: unknown command: `,'
i only want to print the words in the brackets..
here is the sed command
sed -n '/QUEUE/,/CURDEPTH/,/DESCR/ {
s/QUEUE((.*))(.*TYPE(.*))/1/
s/QUEUE((.*))/1/
s/TYPE(.*).*CURDEPTH((.*))/1/
s/CURDEPTH((.*))/1/
s/TYPE(.*).*DESCR((.*))/1/
s/DESCR((.*))/1/
p
}
' | awk '{ if ((NR %2) == 0) { printf("%sn", $0) } else { printf("%s", $0) } }'
and the output…
test.msg.queue 0) DESCR(TQ : 001
thanks…
sample output
1 : dis q(test.msg.queue) CURDEPTH DESCR AMQ0086: Display Queue details. QUEUE(test.msg.queue) TYPE(QLOCAL) CURDEPTH(0) DESCR(TQ : 001)
Advertisement
Answer
You have the wrong expectation. You are asking about the “address” portion of a sed instruction, which specifies on which lines sed should apply the following command. sed does not accept a list of addresses there. It accepts either a single address (often, but not always, a regex), or an address range, expressed as a comma-separated start and end address. There is no address form that accepts a comma-delimited list of three or more regexes.
But sed doesn’t need that; you’re making things too complicated. Regexes already naturally provide for matching a list of separate options. That’s what the | operator is for:
sed -n '/QUEUE|CURDEPTH|DESCR/ {
s/QUEUE((.*))(.*TYPE(.*))/1/
…