Skip to content

Commit 318139c

Browse files
committed
无需写 sed 和 文件名了,因为.sed扩展名的文件中是纯 sed 命令
1 parent 4cb00ff commit 318139c

7 files changed

Lines changed: 64 additions & 1 deletion

File tree

.editorconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ indent_style = space
66
indent_size = 2
77
charset = utf-8
88
trim_trailing_whitespace = true
9-
insert_final_newline = true
9+
insert_final_newline = false
10+
# insert_final_newline = true
1011

1112
[*.md]
1213
trim_trailing_whitespace = false

000-xyz/Linux-Bash-Commands/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ div*10{line 0$}
3434
<div>line 09</div>
3535
<div>line 10</div>
3636
-->
37+
38+
## sed `-f`
39+
40+
```sh
41+
# 执行 sed 脚本,sed 后面指定文件名写在命令行里
42+
$ sed -f test.sed ./test.txt
43+
44+
$ sed -f test.sed ./test.txt >> ./test.out.md
45+
46+
# ✅ -n
47+
$ sed -f test.sed -n ./test.txt
48+
# ❌ -n
49+
$ sed -f -n test.sed ./test.txt
50+
51+
```

000-xyz/Linux-Bash-Commands/sed-replace.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ sed -e "s/<div>/🎉/; s/<\/div>/👻/" ./multi-line-text.txt >> multi-line-text
7272
# sed 's/<div>/👻' | sed 's/</div>/🎉' multi-line-text.txt => multi-line-text.md
7373

7474
echo -e "sed finished"
75+
76+
77+
# echo "this is abc" | sed -e 's/abc/xyz/'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 注释: `.sed`扩展名的文件,是 sed 命令集合专用的,本质上还是一种 shell scirpt
2+
# 无需写 sed 和 文件名了,因为`.sed`扩展名的文件中是纯 sed 命令
3+
s/abc/ABC/
4+
s/xyz/XYZ/
5+
s/ufo/UFO/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
this is 🎉 1
2+
this is 👻 2
3+
this is 🛸 3
4+
this is 🎉 1
5+
this is 👻 2
6+
this is 🛸 3
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 注释: `.sed`扩展名的文件,是 sed 命令集合专用的,本质上还是一种 shell scirpt
2+
# 无需写 sed 和 文件名了,因为`.sed`扩展名的文件中是纯 sed 命令
3+
s/abc/🎉/
4+
s/xyz/👻/
5+
s/ufo/🛸/
6+
7+
8+
# 执行 sed 脚本,sed 后面指定文件名写在命令行里
9+
# $ sed -f test.sed ./test.txt
10+
# $ sed -f test.sed -n ./test.txt
11+
# $ sed -f test.sed ./test.txt >> ./test.out.md
12+
13+
# sed: 12: test.sed: invalid command code <
14+
# <<EOF
15+
16+
# s/abc/xyz/ test.txt
17+
# sed: 4: test.sed: bad flag in substitute command: 't'
18+
19+
# s/abc/xyz/ ./test.txt
20+
# sed: 4: test.sed: bad flag in substitute command: '.'
21+
22+
# 's/abc/xyz/' ./test.txt
23+
# sed: 4: test.sed: invalid command code ' ❌
24+
25+
# sed -e 's/abc/xyz/' ./test.txt
26+
# sed: 2: test.sed: bad flag in substitute command: 's' ❌
27+
28+
# sed -e 's/abc/xyz/' -n ./test.txt
29+
30+
# EOF
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this is abc 1
2+
this is xyz 2
3+
this is ufo 3

0 commit comments

Comments
 (0)