Using Ed Instead of SED

Search and replace with ed

ed can be used in place of sed to modify a file directly.. The format is straightforward if you have an example. Here is an example that changes the mailquota size for Maildir++.

# cat maildirsize
s8909889098
# ed maildirsize << EOF 
> ,s/s[0-9]+ /s552428800 /g 
> wq 
> EOF 
# cat maildirsize
s552428800 
#

Inject search result into replacement string

What if you want to put the results of the last search back into the
string. You can use the ‘&’ symbol for that.

# cat test
this is test
# ed test << EOF
> ,s/is/& a/g
> wq
> EOF
# cat test
this is a test

Leave a Reply

Your email address will not be published. Required fields are marked *