OSDN Git Service

ca1439ed300471981c352bffc3d00546d255804f
[twpd/master.git] / sed.md
1 ---
2 title: sed
3 category: CLI
4 layout: 2017/sheet
5 intro: |
6   Here's home hints on using sed.
7 ---
8
9 ### In place replacements
10
11 #### In GNU sed: use `-i` without arg.
12
13 ```bash
14 sed -i -e 's/foo/bar/' example.md
15 ```
16
17 #### In OSX, `-i ''` is required.
18
19 ```bash
20 sed -i '' -e 's/foo/bar/' example.md
21 ```
22
23 ### File regions
24
25 #### Print until a certain line is met
26
27 ```bash
28 sed '/begin api/q'
29 ```
30
31 #### Print until a certain line is met, but not that line
32
33 ```bash
34 sed '/^# begin/,$d'
35 ```
36
37 #### Print everything after a given line
38
39 ```bash
40 sed -n '/end api/,$p'
41 ```