Search:

PmWiki

pmwiki.org

edit SideBar

Main / Sed

-i = edit file in place

Simple replacement command example:
sed -i 's/oldword/newword/g' file.txt (saves changes) or sed -e 's=old=new=g' file.txt (merely prints file with changes)

Using variable line number for sed:
sed -i "${modline}s/.*/#&/" file.txt

sed lets you make use of other delimiters on the fly, as in replacing / with |:
sed -i 's|dog|yip.yay/horse|g' file.txt which is useful for placing paths.

Using xargs example, on writeable files only:
find . -name foo.txt -perm +222 | xargs -t sed -i 's/foo/bar/g'


Page last modified on September 08, 2020, at 04:51 PM