File tree Expand file tree Collapse file tree
000-xyz/Linux-Bash-Commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ indent_style = space
66indent_size = 2
77charset = utf-8
88trim_trailing_whitespace = true
9- insert_final_newline = true
9+ insert_final_newline = false
10+ # insert_final_newline = true
1011
1112[* .md ]
1213trim_trailing_whitespace = false
Original file line number Diff line number Diff 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+ ```
Original file line number Diff line number Diff 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
7474echo -e " sed finished"
75+
76+
77+ # echo "this is abc" | sed -e 's/abc/xyz/'
Original file line number Diff line number Diff line change 1+ # 注释: `.sed`扩展名的文件,是 sed 命令集合专用的,本质上还是一种 shell scirpt
2+ # 无需写 sed 和 文件名了,因为`.sed`扩展名的文件中是纯 sed 命令
3+ s /abc /ABC /
4+ s /xyz /XYZ /
5+ s /ufo /UFO /
Original file line number Diff line number Diff line change 1+ this is 🎉 1
2+ this is 👻 2
3+ this is 🛸 3
4+ this is 🎉 1
5+ this is 👻 2
6+ this is 🛸 3
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ this is abc 1
2+ this is xyz 2
3+ this is ufo 3
You can’t perform that action at this time.
0 commit comments