Linux Seventh Day: (August 05) Text Processing tool

Source: Internet
Author: User
Tags diff egrep

Linux Seventh Day: (August 05) Text Processing tool


Head-n Specify the first n rows of the right of shipment
TAIL-N Specifies to get the following n rows
Tail-f displaying new additions to files


Cut-d indicates delimiter, default tab
Cut-f the first few fields
Cut-c cut by character


PASTE-D Specifies the delimiter file1 file2
Paste-s all rows are composited on a single line display


Wc-l count rows
Wc-w statistics of words
Wc-c Count bytes
Wc-m Statistic character Count


Sort-r Reverse Sort
Sort-n Sort by number
Sort-f ignoring case
Sort-u Delete duplicate rows
Sort-t c as the field delimiter
Sort-k X


Uniq-c statistics per row repeat occurrences
uniq-d Statistics for Duplicate rows
Uniq-u statistics non-repeating rows


PASTE-D Specifies the delimiter file1 file2
Paste-s all rows are composited on a single line display


diff file1 file2 Comparison two file differences
Diff-u file1 file2 > File3.patch
Patch-b file1 file2 Automatic backup of changed files


Grep:global search REgular expression and Print out of the line
grep "$USER"/etc/passwd
grep ' $USER '/etc/passwd
grep ' WhoAmI '/etc/passwd
grep--color=auot to match the text coloring display
Grep-v show rows that cannot be matched
Grep-i ignoring case
Grep-n Display Line numbers
Grep-c count rows
Grep-o only matching strings are displayed
Grep-q silent, no output information
Grep-a n after n rows
Grep-b n Top N rows
n rows before and after Grep-c N
GREP-E comm1-e COMM2 Multiple or relationships
Grep-w Match Whole Word
Grep-e Use ere


REGEXP Basic Regular Expression BRE
REGEXP extended Regular Expression ERE, grep-e, Egrep


Character matching
. Match any single character
[] matches any single character within the specified range
[^] matches any single character outside the specified range
Metacharacters
[:d igit:] All numbers
[: Lower:] All lowercase letters
[: Upper:] All uppercase letters
[: Alpha:] All letters
[: Alnum:] All alphanumeric
[:p UNCT:] All punctuation
[: Space:] Space and Tab


Number of Matches
* matches the preceding character any number of times, including 0 times
. * Any character of any length
\? Matches the preceding character 0 or 1 times
\+ matches the preceding character at least 1 times
\{n\} matches the preceding character n times
\{m,n\} matches the preceding character at least m times, up to N times
\{,n\} matches the preceding character up to n times
\{n,\} matches the preceding character at least n times


Position anchoring
^ Beginning anchor, user mode leftmost
& End anchors for the right side of the pattern
^ $ for pattern matching whole line
^& Empty Line
^[[:space:]]*$ Blank Line
\< or \b The first anchor for the left side of the word pattern
\> or \b Ending anchor for the right side of the word pattern
\< \> Match Whole word


Group
\( \)


Egrep and extending to regular expressions


Character matching
Egrep = Grep-e
. Any single character
[] Specify the range of characters
[^] characters not in the specified range


Number of Matches
* matches the preceding character any number of times
? Matches the preceding character 0 or 1 times
{m} matches M-Times
{m,n} at least m times, up to N times


Extending regular Expressions


Position anchoring
^ Beginning of the line
$ End of line
\< \b First language
\> \b End of the language


Group
()
\1 \2 back to reference


C|cat C or Cat
(C|C) at cat or cat

Linux Seventh Day: (August 05) Text Processing tool

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.