The awk
solution is what I would use, but a slightly smaller process to launch is sed
and it can produce the same results, but by substituting the PATH= part of the line with ""
, i.e.
sed -n 's/^Path=//p' file
The -n
overrides sed
s default behavior of 'print all lines' (so -n
= no print),
and to print a line, we add the p
character after the substition. Only lines where the substitution happens will be printed.
This gives you the behavior you have asked for, of grep
ing for a string, but removing the Path=
part of the line.
If, per David Foerster's comments, you have a large file and wish to stop processing as soon as you have matched and printed the first match to 'Path=', you can tell sed to quit, with the q
command. Note that you need to make it a command-group by surrounding both in { ..}
and separating each command with a ;
. So the enhanced command is
sed -n 's/^Path=//{p;q;}` file
IHTH