1.1 Take out the 908 of the A.txt in these three numbers:
Instance:
[email protected] tmp]# cat a.txt
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
I am ZJC 1046 (in) 908 jiayou
[Email protected] tmp]#
The result is:
[email protected] tmp]# cat A.txt
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
I am ZJC 1046 (in)908 jiayou
[Email protected] tmp]#
[[Email protected] tmp]# sed ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt|sed-n ' 3p '
908
[Email protected] tmp]#
Operation process (for reference only):
[email protected] tmp]# cat A.txt
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
I am ZJC 1046 (in) 908 jiayou
[[Email protected] tmp]# sed ' 3p ' a.txt forgot to add parameter-N to cancel default output
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
I am ZJC 1046 (in) 908 jiayou
I am ZJC 1046 (in) 908 jiayou
[[email protected] tmp]# sed-n ' 3p ' a.txt add parameters to restore normal output only matching content
I am ZJC 1046 (in) 908 jiayou
[[email protected] tmp]# sed-n ' 3s#^.*88) \ (. *) JIA.*$#\1#GP ' a.txt escape multibyte wrong
Sed:-E expression #1, char 27:unmatched (or \ (
[[Email protected] tmp]# sed ' 3s#^.*88) \ (. *) jia.*$#\1#g ' a.txt escaped multibyte or not
Sed:-E expression #1, char 26:unmatched (or \ (
[[Email protected] tmp]# sed ' 3s#^.*88) \ (. *\) jia.*$#\1#g ' a.txt escape character is correct after normal
Aaaaaaaaaaaaa
BBBB bbbbbbbbbbbbbb but found that the default output is output by default because there is no add-n?
908
[[email protected] tmp]# sed-n ' 3s#^.*88) \ (. *\) jia.*$#\1#g ' a.txt added-n No content
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt haven't found the reason
[[Email protected] tmp]# sed ' 3s#^.*88] \ ([0-9].*\) jia.*$#\1#g ' a.txt haven't found a reason
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB haven't found a reason yet .
908
[[Email protected] tmp]# sed ' 3s#^.*88] \ ([0-9].*\) jia.*$#\1#g ' a.txt haven't found a reason
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
[[Email protected] tmp]# sed ' s#^.*88] \ ([0-9].*\) jia.*$#\1#g ' a.txt haven't found a reason
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
[[Email protected] tmp]# sed ' 3s#^.*88] \ ([0-9].*\) jia.*$#\1#g ' a.txt haven't found a reason
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt still think it is-n
[Email protected] tmp]#
[[email protected] tmp]# sed-nr ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt is not add-r?
Sed:-E expression #1, char 32:unmatched) or \)
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt haven't found the reason
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' A.txt|xargs ls
I haven't found a reason.
A.txt P.txt Test.txt
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' A.txt|xargs cat
I haven't found a reason.
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt
I haven't found a reason.
[[Email protected] tmp]# sed ' 3s#^.*88] \ ([0-9].*\) jia.*$#\1#g ' a.txt haven't found a reason
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
[[Email protected] tmp]# sed ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt|sed ' 3p '
Plus one sed.
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
908
[[Email protected] tmp]# sed ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#g ' a.txt|sed-n ' 3p '
Cancel default Output
908
[email protected] tmp]# cat A.txt
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
I am ZJC 1046 (in) 908 jiayou
[Email protected] tmp]#
[[Email protected] tmp]# sed ' 3s#^.*88) \ ([0-9].*\) jia.*$#\1#gp ' A.txt Oh, I forgot to add P
Aaaaaaaaaaaaa
BBBB BBBBBBBBBBBBBB
908
908
[[email protected] tmp]# sed-n ' 3s#^.*88) \ ([0-9].*\] jia.*$#\1#gp ' a.txt Add a-N to o
908
[Email protected] tmp]#
This article is from the "[email protected]" blog, please be sure to keep this source http://jinchengzheng.blog.51cto.com/10798482/1843245
An exercise on the sed of the Three Musketeers of Linux