SED - zhuje/openshift-wiki GitHub Wiki

Delete

sed -i '' '/^text to delete/ d' file.txt

Replace

image

https://stackoverflow.com/questions/38678692/shell-script-edit-files-line


Edit file in place

sed -i '' 's/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g' filename image

https://stackoverflow.com/questions/12696125/sed-edit-file-in-place


Append

Append at the end of the file is usually done but echo but it can also be done with sed.

$ echo "This is last line" >>file

OR

sed -i -e '$a\'$'\n''This line was appended at the end.' test.txt image https://stackoverflow.com/questions/61144810/how-to-append-a-line-at-the-end-of-the-file-using-sed


Comment out a line

sed -i '\%foo-keyword% s/^/#/' file image

https://askubuntu.com/questions/1139756/add-pound-sign-at-begining-of-the-line-matching-search-string-file-path

Uncomment line

sed '/bean/s/^# *//' file.txt image

https://stackoverflow.com/questions/22119407/how-to-find-a-pattern-in-file-entry-remove-leading-hash-and-redirect-all-entrie

⚠️ **GitHub.com Fallback** ⚠️