Add example for sed

Add a line after the line that matches the pattern (e.g. add a new line with "world" after the line with "hello")
This commit is contained in:
Bonnie I-Man Ng 2023-08-11 00:25:22 +08:00 committed by GitHub
parent 6576e5a685
commit 212326d7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -564,7 +564,7 @@ sed '$a\'
##### Add string to beginning of every line (e.g. 'bbo') ##### Add string to beginning of every line (e.g. 'bbo')
```bash ```bash
sed -e 's/^/bbo/' file sed -e 's/^/bbo/' filename
``` ```
##### Add string to end of each line (e.g. "}") ##### Add string to end of each line (e.g. "}")
@ -577,6 +577,13 @@ sed -e 's/$/\}\]/' filename
sed 's/.\{4\}/&\n/g' sed 's/.\{4\}/&\n/g'
``` ```
##### Add a line after the line that matches the pattern (e.g. add a new line with "world" after the line with "hello")
```bash
sed '/hello*/a world' filename
# hello
# world
```
##### Concatenate/combine/join files with a separator and next line (e.g separate by ",") ##### Concatenate/combine/join files with a separator and next line (e.g separate by ",")
```bash ```bash
sed -s '$a,' *.json > all.json sed -s '$a,' *.json > all.json