Reputation: 10143
With Vim's global command, it is possible to chain multiple commands with |
(pipe) symbol when matching some lines, for example:
g/match/ s/11/00/ | s/22/11/g
Is this also possible with sed without repeating the match
regex?
sed -e '/match/ s/11/00/ ; /match/ s/22/11/g ' $file
If not, is it possible to do this with perl?
Upvotes: 1
Views: 682
Reputation: 10189
You could use:
echo "->11,22<-
->01,20<-" | sed '/11/ {s/11/00/g; s/22/11/g}'
Output is:
->00,11<-
->01,20<-
/11/
restricts the s
commands inside its { ... }
block only to matching linesUpvotes: 2