An exercise on the sed of the Three Musketeers of Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.