Deano
Deano

Reputation: 12200

How to pass file name to sed

I'm trying the following

grep 178 * | sed 's/178/179/g'

Results:

ifcfg-bond0:IPADDR=10.30.10.179
ifcfg-bond1:IPADDR=10.30.8.179
rule-bond0:from 10.30.10.179 table sip

However when I try to pass -i option to sed to make changes permanent, I get the following.

grep 178 * | sed -i 's/178/179/g'
sed: no input files

Any ideas?

Upvotes: 4

Views: 4492

Answers (2)

Jens
Jens

Reputation: 72657

What about avoiding a fork/pipe with

 sed -i 's/178/179/g' *

Files that don't contain 178 won't be affected.

The original in your question can't work because -i replaces files in-place, but you pipe the data in via stdin (for which in-place substituion just makes no sense).

Upvotes: 2

Deano
Deano

Reputation: 12200

This is how I got it to work! :)

 grep -rl 178 ../network/ | xargs sed -i 's/178/179/g'

Upvotes: 8

Related Questions