To get something like grep | cut
you can use sed -n s/A/B/p
.
By default, sed
prints every line after all commands are processed. You can silence all output that you don't explicitly print from a command with sed -n
.
The s
command takes the form s/$FIND/$REPLACE/$FLAGS
. Specifically, the p
flag prints the line whenever a replacement is made.
With these combined, you can easily match and cut:
sed -nE "s/email2 = (.+)/\1/p" < /etc/emails.conf
In fact, this is strictly more powerful than grep | cut
because you can use an arbitrary replacement pattern.
(The -E
option enables modern regex, which allows you to reference capture groups in the replacement pattern. For a simple cut, you can get away without it by using more clever patterns.)
cat
:grep email2 /etc/emails.conf | ...
– Carlos Campderrós May 04 '15 at 15:59result="email2"
-- what are you really trying to do? – glenn jackman May 05 '15 at 01:25