例如:有個文件test的內容以下: ert fff ** [abcfd] 123 324 444 [rty] ** fgfgf
怎麼能截取 [abcfd] 123 324 444 [rty] 這一部分出來呢?
[root@linux-128 test]# sed -n '/\[abcfd\]/,/\[rty\]/'p 1.txt [abcfd] 123 324 444 [rty]
[root@linux-128 test]# sed -n '/\[abcfd\]/'p 1.txt [abcfd
sed轉換大小寫 http://ask.apelearn.com/question/7758linux
[root@linux-128 test]# sed 's/\b[a-z]/\u&/g' 1.txt Ert Fff ** [Abcfd] 123 324 444 [Rty] ** Fgfgf
[root@linux-128 test]# sed 's/[a-z]/\u&/g' 1.txt ERT FFF ** [ABCFD] 123 324 444 [RTY] ** FGFGF
[root@linux-128 test]# cat 2.txt ERT FFF ** [ABCFD] 123 324 444 [RTY] ** FGFGF [root@linux-128 test]# sed 's/[A-Z]/\l&/'g 2.txt ert fff ** [abcfd] 123 324 444 [rty] ** fgfgf
[root@linux-128 test]# cat 3.txt askdj aslkd aslkdjf3e skdjfsdfj sdkfjk fsdkfjksdjfkjsdf 12sdfesdf aslkdjfkasdjf asdlfkjaskdfj
[root@linux-128 test]# sed -r 's/(.*)/&123/'g 3.txt askdj123 aslkd aslkdjf3e123 skdjfsdfj123 sdkfjk123 fsdkfjksdjfkjsdf123 12sdfesdf123 aslkdjfkasdjf asdlfkjaskdfj123
[root@linux-128 test]# sed -r 's/(^a.*)/&123/'g 3.txt askdj123 aslkd aslkdjf3e123 skdjfsdfj sdkfjk fsdkfjksdjfkjsdf 12sdfesdf aslkdjfkasdjf asdlfkjaskdfj123
[root@linux-128 test]# sed -r 's/(^a.*)/\1123/'g 3.txt askdj123 aslkd aslkdjf3e123 skdjfsdfj sdkfjk fsdkfjksdjfkjsdf 12sdfesdf aslkdjfkasdjf asdlfkjaskdfj123
[root@linux-128 test]# cat 3.txt askdj aslkd aslkdjf3e skdjfsdfj sdkfjk fsdkfjksdjfkjsdf 12sdfesdf aslkdjfkasdjf asdlfkjaskdfj
[root@linux-128 test]# sed '/sdkfjk/,$'d 3.txt askdj aslkd aslkdjf3e skdjfsdfj
[root@linux-128 test]# cat 2.txt ERT FFF ** [ABCFD] 123 324 444 [RTY] ** FGFGF [root@linux-128 test]# sed '/123/{p;:a;N;$!ba;d}' 2.txt ERT FFF ** [ABCFD] 123
[root@linux-128 test]# cat 2.txt ERT FFF ** [ABCFD] 123 324 444 [RTY] ** FGFGF
方法一:code
[root@linux-128 test]# sed -n '1,10{/123/p}' 2.txt 123
方法二:字符串
[root@linux-128 test]# sed -n '1,10'p 2.txt |sed -n '/123/'p 123