Shell: Regular expressions and text processing

Source: Internet
Author: User

Job One: organize regular expression Blogs
Job Two: grep jobs (regular expressions and character processing)
Target file/etc/passwd, using the grep command or Egrep
1. All rows containing root are displayed:
2. Output any rows that contain bash, and also output the contents of the next two lines, followed by the row:
3. Shows how many lines contain nologin.
4. Shows that the rows contain root and the line number is output.
5. Displays the file in the
6. New user
Abominable
Abominate
Anomie
Atomize
Write regular expressions and match them up
7. Built four users
Alex213sb
wpq2222b
Yh438pig
egon666
Egon

Filter out the user name consists of a letter + number + letter Line
8. Displays all filenames containing root in/etc directory
9. Filter out all comments and all blank lines in/etc/ssh/sshd_config


Job Three: SED job:/etc/passwd file as Template

1. Delete the first character of each line of the file.

2. Delete the second character of each line of the file.

3. Delete the last character of each line of the file.

4. Delete the second-to-last character of each line of the file.

5. Delete the second word in each line of the file.

6. Delete the second-to-last word in each line of a file.

7. Delete the last word in each line of the file.

8, swaps the first character and the second character of each line.

9, swaps the first character and the second word of each line.

10, swap the first word and the last word of each line.

11, delete all the numbers in a file.

12, remove all spaces at the beginning of each line.

13, replace any spaces that appear in the file with tabs.

14, enclose all uppercase letters in parentheses ().
Sed-r ' s/[a-z]/(&)/g '/etc/passwd
15, print 3 times per line.

16, only the first word of each line is displayed.

17, print the first word and the third word of each line.

18, use the command to get the format MM/YY/DD date format, combined with the pipeline, change it to MM;YY;DD format

Shell: Regular expressions and text processing

Related Article

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.