sed: Added command for excluding lines while printing (#984)
Co-authored-by: Rico Sta. Cruz <rstacruz@users.noreply.github.com>
This commit is contained in:
parent
959b471fb6
commit
42950dfac7
29
sed.md
29
sed.md
|
@ -6,36 +6,51 @@ intro: |
|
|||
Here's some hints on using sed.
|
||||
---
|
||||
|
||||
### In place replacements
|
||||
## In place replacements
|
||||
|
||||
#### In GNU sed: use `-i` without arg.
|
||||
### In-place replacement (GNU)
|
||||
|
||||
```bash
|
||||
sed -i -e 's/foo/bar/' example.md
|
||||
```
|
||||
|
||||
#### In OSX, `-i ''` is required.
|
||||
In GNU sed: use `-i` without arg.
|
||||
|
||||
#### In-place replacement (BSD)
|
||||
|
||||
```bash
|
||||
sed -i '' -e 's/foo/bar/' example.md
|
||||
```
|
||||
|
||||
### File regions
|
||||
In OSX, `-i ''` is required.
|
||||
|
||||
#### Print until a certain line is met
|
||||
## File regions
|
||||
{:.-three-column}
|
||||
|
||||
### Print until a certain line is met
|
||||
|
||||
```bash
|
||||
sed '/begin api/q'
|
||||
```
|
||||
|
||||
#### Print until a certain line is met, but not that line
|
||||
### Print until a certain line is met, but not that line
|
||||
|
||||
```bash
|
||||
sed '/^# begin/,$d'
|
||||
```
|
||||
|
||||
#### Print everything after a given line
|
||||
### Print everything after a given line
|
||||
|
||||
```bash
|
||||
sed -n '/end api/,$p'
|
||||
```
|
||||
|
||||
Print after a given line is found.
|
||||
|
||||
### Print everything except matching
|
||||
|
||||
```bash
|
||||
sed -n '/regex/d;'
|
||||
```
|
||||
|
||||
Print everything except lines matching regex. Useful for printing files with comments.
|
||||
|
|
Loading…
Reference in New Issue