Unix Shell Programming Notes series (II)

Source: Internet
Author: User

First, regular expression

Period. Matches any single character, such as a. Represents two characters after a match

^//Match the beginning of the line, such as ^w, to match the W at the beginning

$//matches the end of a line, such as x$, that matches the row at the end of the line, ^insert$ represents only the rows that contain the insert

\//plus special characters to be removed in special characters

^$//Match blank line

*//Match 0 or several characters, x* means match 0 or several consecutive x,xx* means match 1 or more consecutive x,.* represents 0 or several characters, w.*s represents any string with the end of W beginning S

These characters are only useful for searching strings, such as/^[a-z]/, which matches lines that begin with uppercase letters;

[^a-z]//match characters except uppercase

{min,max\}//Specifies a range of matches, the preceding regular expression repeats at least min times, up to Max Times

\ (... \)//Save matching strings, store matching strings in parentheses in the next register (1-9)

[TT]//Match lowercase or uppercase T

[A-z]//match any lowercase letter

[A-za-z]//Match lowercase or uppercase letters

[^ character table]//Match any characters that are not in the character list

Cut

Cut-c1-a//Extract the results of each line from the first character to the last character in a file

Cut-c1-5 A//extract the result of each line from the first character to the 5th character in a file

Cut-d:-f1/etc/shadow//Shadow each line in the file as: The result of the first segment of the split is extracted, that is, the user name

Cut-d:-f1,6/etc/passwd//Each line in the passwd file is extracted by the result of the first and sixth segments of the split, that is, the user name and the user host directory

CUT-F1 A//here does not add the-D parameter for the cut by default tab as the delimiter

\ t//Indicates tab

Paste//merge rows

Paste-d ' + ' a b//to merge each line in A and B files, split with +, no-d parameter is delimited by tabs by default

Paste-s A//merges all rows in a file into one line

SED//stream editor, edit data with

sed command file

Sed ' s/unix/unix/g ' intro//Replace all Unix in the intro file with UNIX and print it on screen without changing the original file (s is the substitution function, G is the global option to ensure that multiple Unix in a row can be replaced)

Sed-n ' 1,2p '/etc/passwd//Show only the first two lines of the passwd file

Sed-n '/root/p '/etc/passwd//display only rows containing the root string in the passwd file

Sed-n ' 1,2d '/etc/passwd//delete passwd files in lines 1 and 2

Sed ' 5d ' A//delete line 5th of a file

Sed '/[tt]est/d ' A//delete the line containing test or test in a file

Sed ' s/...//' A//delete the first 3 characters of each line in a file

Sed ' s/...$//' A//delete the second 3 characters of each line in a file


TR//For converting characters from standard input, without changing the original file

TR From-chars To-chars

TR e x </etc/passwd

TR ' [A-z] ' [A-z] ' </etc/passwd//convert lowercase letters in passwd files to uppercase

Octal values for commonly used ASCII characters

Bell 7

BACKSPACE 10

tab 11

New Row 12

Line break 12

Change page 14

Enter 15

Escape 33


Tr-s ' A//compress extra spaces in a file

Tr-d ' A//remove the space in a

TR ' x ' x '//all uppercase to lowercase

TR ' () ' {} '//All left parenthesis to left curly brace, right parenthesis to closing curly brace

TR ' [A-z] ' [n-za-m] '//The characters of all a-m are converted to n-z,n-z respectively to A-m

Tr-d ' [0-9] '//Delete all numbers

Grep

grep pattern Files
Grep-i//Case insensitive

GREP-V//Reverse selection, do not display lines that include patterns

GREP-L//Display the file name of the containing mode

Line number in the Grep-n//file that matches the specified pattern

Sort//sorting, by default in ascending order by encoding

Sort-u//Remove Duplicate rows

Sort-r//reverse order

Sort-o//followed by filename, output directed to file

Sort-t:-K 3/etc/passwd//Sort by User ID

Uniq//Remove consecutive rows of duplicates

Uniq Input-files Out-files

uniq-d//Show Duplicate rows

SORT/ETC/PASSWD |cut-f1-d: |uniq-d//Find duplicate user name

Awk,perl

Who|cut-f1-d ' |grep ' \w\{4,\} '//Find logged-in users with at least 4 characters in the system

Cut-d:-F 1,3/etc/passwd | grep ' [0-9]\{3,\} ' | Cut-d:-F 1//Isolate users with a user ID number greater than 99 in the system

Cut-d:-F 1,3/etc/passwd |grep ' [0-9]\{3,\} ' | Wc-l//Statistics of users greater than 99

Ls-l | SORT-NRK 5//By file size descending sequence all files in the directory

This article is from the "on the" blog, please be sure to keep this source http://weiwang.blog.51cto.com/2609379/1618314

Unix Shell Programming Notes series (II)

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.