Zhangminghui-linux Basic Command Learning-3

Source: Internet
Author: User

"Linux operations are applied disciplines, and more will result."




View only the contents of line 20th to 30th within the Test.txt file (50 rows)

Setting up an experimental environment

[email protected] ~]# seq >test.txt

[email protected] ~]# cat Test.txt


Method One:

[Email protected] ~]# head-30 test.txt|tail-11



Method Two:

The SED stream Editor enables the file to be added, deleted, changed, replaced, checked

[[email protected] ~]# sed-n ' 20,30 ' P test.txt

Method Three:

AWK Filter Output content processing log text nr denotes line number

[[email protected] ~]# awk ' 19<nr && nr<31 ' test.txt

View the contents of line 10th

[Email protected] ~]# awk ' nr==10 ' test.txt


Method Four:

Filtering with grep

grep 20-a-N test.txt in addition to matching 20 of this line and displays the next n rows

grep 30-b -n test.txt , in addition to matching 30, displays the first n rows

grep 25-c-N test.txt , in addition to matching the 30 line, displays the front and back n rows

[Email protected] ~]# grep 20-a test.txt

[Email protected] ~]# grep 30-b test.txt

[[email protected] ~]# grep 25-c 5 test.txt





Seq Sequence

[email protected] ~]# seq

[[email protected] ~]# SEQ 5

[[email protected] ~]# seq 10-2 0

[email protected] ~]# seq 2

1-10 writing across the





Replace all the characters in the/ZMG directory and its subdirectories that contain Xinwanjia with the name of the. sh extension as Xwj

sed [-i] ' s#a#b#g ' A is the replacement of the content, B is replaced by the content, the parameter I will modify the contents of the file, and vice versa will not fix a content


Zhangminghui-linux Basic Command Learning-3

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.