help needed with SED

Hello!

I have a "problem" with sed... In a log, I'm wondering how to have the name of the application when "INCIDENT" is in the file...
The name of the application is before "INCIDENT".
For this example, The result should be "SPVP0005"

thanks for your help!

By awk:

awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' infile
1 Like

Thanks for your quick answer but that didn't work...

Sorry this is in French :frowning: ... but apparently, it didn't like /{app=$3}/
The translation is not really difficult... Context error

Hi Castelior,

If you need in sed, this it seems to work:

sed -e '/Application/b;/INCIDENT/b' -e d inputfile |  sed -n 's/Application : //;/INCIDENT/{g;1!p;};h'

Maybe some sed expert could say us how to join both sed commands.

Or another option with awk:

awk '/Application/{A=$3};/INCIDENT/{print A}' inputfile

Hope it helps.

Regards

Ruby(1.9+)

$ ruby -ane 'a=$F[2] if /^Application/; puts a if /INCIDENT/' file
SPVP0005

sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' infile
awk '/^App/{x=$NF}/INCIDENT/{print x}' infile
# sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' tst
SPVP0005
# awk '/^App/{x=$NF}/INCIDENT/{print x}' tst
SPVP0005
1 Like

Strange it worked for me.

$awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' file5
SPVP0005

P.S. file5 has a copy of the data you posted.

1 Like

That works well!!

thanks a lot!:slight_smile: