tldr/pages/common/sed.md

26 lines
855 B
Markdown
Raw Normal View History

2013-12-11 10:50:11 +00:00
# sed
> Edit text in a scriptable manner.
2022-11-12 13:05:16 +00:00
> See also: `awk`, `ed`.
> More information: <https://www.gnu.org/software/sed/manual/sed.html>.
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
- Replace all `apple` (basic regex) occurrences with `mango` (basic regex) in all input lines and print the result to `stdout`:
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
`{{command}} | sed 's/apple/mango/g'`
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
- Execute a specific script [f]ile and print the result to `stdout`:
2022-11-12 13:05:16 +00:00
`{{command}} | sed -f {{path/to/script.sed}}`
2022-11-12 13:05:16 +00:00
- Replace all `apple` (extended regex) occurrences with `APPLE` (extended regex) in all input lines and print the result to `stdout`:
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
`{{command}} | sed -E 's/(apple)/\U\1/g'`
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
- Print just a first line to `stdout`:
2013-12-11 10:50:11 +00:00
2022-11-12 13:05:16 +00:00
`{{command}} | sed -n '1p'`
2022-11-12 13:05:16 +00:00
- Replace all `apple` (basic regex) occurrences with `mango` (basic regex) in all input lines and save modifications to a specific file:
2022-11-12 13:05:16 +00:00
`sed -i 's/apple/mango/g' {{path/to/file}}`