3 ms·
In this particular example, ‘unnecessary use of cat’ is accompanied by ‘unnecessary use of grep’. cat input | grep '^x' | sed 's/foo/bar/g' → sed '/^
by kps 8y ago
In this particular example, ‘unnecessary use of cat’ is accompanied by ‘unnecessary use of grep’.
cat input | grep '^x' | sed 's/foo/bar/g'
→
sed '/^x/s/foo/bar/g' <input
- irishsultan 8y agoThat's not the same thing. The sed output will still keep lines not starting with x (just not replacing foo with bar in those) where grep will filter those out.
- kps 8y agoYeah, Muphry's law at work. Corrected version: sed -n '/^x/s/foo/bar/gp' <input This may be an inadvertent argument for the ‘connect simpler tools’ philosophy.