Several commonly used text-processing shell commands: Find, grep, sort, uniq, sed, awk

Source: Internet
Author: User

Find File Lookup

Find txt and PDF files

Find. \ (-name "*.txt"-o-name "*.pdf" \)-print

Find files that start with all letters

Find. -name "[a-a]*"

Find all non-txt text with negative parameters

Find. ! -name "*.txt"-print

Specify the search depth to print out the current directory file (depth is 1)

Find. -maxdepth 1-type F

Regular way to find. txt and PDF

Find. -regex ". *\ (\.txt|\.pdf\) $"-iregex: the case-insensitive regular

Find files with property 755 under Directory

Find. -prem 755

Find files that belong to the main root

Find-user Root

Looking for files larger than 2k

Find. -type f-size +2k

File follow-up action found

Delete all AVI files in the current directory

Find. -type f-name "*.avi"-delete

Perform actions (powerful exec)

Find. -type f-user root-exec chown root {} \; Change ownership in the current directory to root
grep Text Search

Filter out the line where the string ' str ' is located in file

Grep-v "str" file

Find the line in the file that the time is in 2017:22:50~2017:22:59

Grep-e "2017:22:5[0-9]" file

Find rows that do not include 360 in the file files

Grep-e "^[^360]" file

Find rows in file files that include W and t

Grep-e "W*t" file

Find rows greater than 560 less than 893 in file files

Grep-e "[5-8][6-9][0-3]"

Find a row with two 9 in a file

Grep-e "9{2}" file

Find rows that are larger than two 9

Grep-e "9{2,}" file

Finding blank lines in a file

Grep-e "^$" file

Find included? The line

grep "?" File

Find lines in a file that start with W

Grep-e "^w" file

Find rows in a file that are not preceded by W

Grep-e "^[^w]" file
awk Data Flow processing tool

Find each column in the log file

awk ' {print $} ' Log.log

Find the first and seventh columns in a file

awk ' {print%$1 ' \ t ' $7} ' Log.log

~ Match IP address statistics for 192.168.10.2.!~ is not matched

Cat File | awk ' $!~/192.168.10.2/' | grep ' php ' |WC-|
Sed line positioning

Prints only the second row, not the data for the other rows

Sed-n ' 2 ' p file

Records from the first row to the Nineth row

Sed-n ' 1,9 ' p file

Print lines that match PHP

Sed-n '/php/p file

Print all rows from line nineth to match PHP

Sed-n ' 9,/php/' p file

Delete all first and second rows (non-file delete)

Sed ' d ' file
Uniq use of row positioning

Number of occurrences of repeated rows that are printed immediately

Uniq-c file

To print only duplicate rows

uniq-d file

Count all access IPs for Apache websites and print statistics

awk ' {print '} '/var/log/httpd/access_log | Sort | Uniq-c
Use of sort sorting

To sort the letters of the Holy market.

Sort file

Sort the files in descending order of letters

Sort-r file

Sort the first column after the split

Cat File | SORT-T:-k1-r

Several commonly used text-processing shell commands: Find, grep, sort, uniq, sed, awk

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.