Extract a value using sed (easy)

I have this command to replace the version value from PROGRAM (for example here PROGRAM == player) by NEWVERSION

sed "/^ *$PROGRAM:/{N; s/[^:]*$/ $NEWVERSION/;}" -i $PRDFILE
  player:
    version: V6R2013xD3HF5v1
  player_old:
    version: V6R2013xD3HF5v1
  partchecker:
    version: 6.142.1-rc6

But now, I would like just extract PROGRAM Version without replacing the string.
(Just get V6R2013xD3HF5v1 if program == player)

Thank you for your help

Try

sed -n "/^ *$PROGRAM:/{n;p}" file
    version: V6R2013xD3HF5v1

or, if "version:" also should disappear, try

sed -n "/^ *$PROGRAM:/{n;s/^ *version: //;p}" file
V6R2013xD3HF5v1

I strongly recommend reading man sed !

1 Like

I will do it this week-end, I swear :wink:

Thanks !