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?
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 lines
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.