Date created: Monday, January 27, 2025 11:09:33 AM. Last modified: Tuesday, January 28, 2025 9:39:24 AM
'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
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