0

how to combine the below sed commands in Linux

sed -rn 's/.*MsgFlow="([^"]*)".*/\1/p'  ADVQCC_OUTPUT_BRK1

and

sed -n 's:.*<ProcessDtm>\(.*\)</ProcessDtm>.*:\1:p' ADVQCC_OUTPUT_BRK1

Thanks

2
  • 1
    Can you show input file and desired output? Nov 30, 2017 at 10:11
  • 2
    looks like you are trying to parse xml/html content. Post your input file content. sed is NOT a proper tool for such case Nov 30, 2017 at 10:32

2 Answers 2

1

Usually, you can simply concatenate sed commands like several s commands with an embedded semicolon:

sed 's/some/another/;s/stuff/thing/'

In your case, one command uses extended regular expressions (ERE), the other basic regular expressions, so you need to convert one or the other:

sed -n 's/.*MsgFlow="\([^"]*\)".*/\1/p;s:.*<ProcessDtm>\(.*\)</ProcessDtm>.*:\1:p' ADVQCC_OUTPUT_BRK1

or with ERE:

sed -En 's/.*MsgFlow="([^"]*)".*/\1/p;s:.*<ProcessDtm>(.*)</ProcessDtm>.*:\1:p' ADVQCC_OUTPUT_BRK1

Remark: I changed -r to -E for selecting ERE, because this is understood by more versions of sed.

0

I think the more closer variant of two command combination will be (POSIXly):

sed -ne 's/.*MsgFlow=\"\([^"]*\)\".*/\1/p' -ne 's/.*<ProcessDtm>\\\(.*\\\)<\/ProcessDtm>.*/\1/p' ADVQCC_OUTPUT_BRK1

Or simpliest:

sed -e 's/.*MsgFlow=\"\([^"]*\)\".*/\1/' -e 's/.*<ProcessDtm>\\\(.*\\\)<\/ProcessDtm>.*/\1/' ADVQCC_OUTPUT_BRK1

But i need input example to get more exact result.

1
  • Why are you escaping double quotes inside the single quote script? Why those `\\`?
    – Philippos
    Nov 30, 2017 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .