Date created: Monday, January 27, 2025 11:09:33 AM. Last modified: Monday, February 3, 2025 3:03:39 PM

'sed' - Notes

Replace

Search and replace, returning the changed output to stdout:

sed "s/aaa/bbb/" /path/to/input

 

Global search and replace, returning the changed output to stdout

sed "s/aaa/bbb/g" /path/to/input

 

Search and replace text between start "foo" and end "bar" markers, including the markers:

sed -E "/foo/,/bar/d" 0001_initial.py

 

Replace In Place

Search and replace within a file, without creating a backup file:

sed -i '' 's/search/replace/' /path/to/input

 

Search and replace within a file, and create a backup file:

sed -i '.bak' 's/search/replace/' /path/to/input

 

Delete

Delete only the first occurance of a pattern in a file

sed -i '0,/foo/{/foo/d;}' "$filename"

 


Previous page: 'rkhunter' - Notes
Next page: 'sort' - Notes