Linux Seven ways to view file line numbers

Source: Internet
Author: User

The contents of the file are as follows, requiring the line number corresponding to the file content

[Email protected] ~ 13:01:16]# cat 123.txt name:i am gaoyangbirthday:19961025what the fuck!!!!

1, Cat-n 123.txt

[Email protected] ~ 13:54:38]# cat-n 123.txt 1name:i am Gaoyang 2 3birthday:19961025 4 5what the FU Ck!!!!

2, NL 123.txt

[[Email protected] ~ 13:57:56]# nl 123.txt #===> do not show blank line 1name:i am Gaoyang 2birthday:19961025 3what the fuck!!!!

3, Grep-n ". *" 123.txt

[Email protected] ~ 13:58:56]# grep-n ". *" 123.txt 1:name:i am gaoyang2:3:birthday:199610254:5:what the fuck!!!!

4. awk ' {print nr,$0} ' 123.txt

[Email protected] ~ 14:01:15]# awk ' {print nr,$0} ' 123.txt1 name:i am gaoyang2 3 birthday:199610254 5 what the fuck!!!!

5, Less-n 123.txt

[[Email protected] ~ 14:01:19]# less-n 123.txt 1 name:i am Gaoyang 2 3 birthday:19961025 4 5 What the fuck!!!! 123.txt (END)

6, sed ' = ' 123.txt |sed ' n;s#\n# #g '

[[Email protected] ~ 14:02:23]# sed ' = ' 123.txt |sed ' n;s#\n# #g ' 1 name:i am gaoyang2 3 birthday:199610254 5 What the fuck !!!!

7. Vim 123.txt:set nu

1 name:i am gaoyang  2   3 birthday:19961025  4    5 what the fuck!!!!                                                                                                                                                                     :set nu 


Linux Seven ways to view file line numbers

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.