Linux Shell Command (2)-CAT/CUT/paste/SED/TR/grep/sort/uniq

Source: Internet
Author: User

Who

    • All users currently logged in to the system

Cat

    • Examine the contents of a file

WC-l

WC-W

WC-C

    • Get a count of the total number of lines, words, and characters of information contained in a file

 

Cut

Cut-cchars File

 
$ Who
 
 
 
Root console Feb 24 08:54
 
 
 
Steve tty02 Feb 24 :55
 
 
 
George tty08 Feb 24
 
 
Dawn tty10 Feb 24 :55
 
 
 
$ Who | cut-c1-8 extract the first 8 characters
 
 
 
Root
 
 
 
Steve
 
 
 
George
 
 
 
Dawn
 
 
 
$
 
$ Who | cut-c1-8, 18-
 
 
 
Root Feb 24 :54
 
 
 
Steve Feb 24 :55
 
 
George Feb 24
 
 
 
Dawn Feb 24 :55
 
 
 
$

-DAnd-FOptions

Divide parameters into multiple fields using the-D delimiter.-F specifies which fields

If no delimiters are specified, tab is used as the delimiters.

 
$ CAT/etc/passwd
 
 
 
Root: *: 0: 0: The Super User: // usr/bin/KSh
 
 
 
Cron: *: 1: 1: Cron DaemonForPeriodic tasks :/:
 
 
 
Bin: *: 3: 3: The owner of system files :/:
 
 
Uucp: *: 5: 5:/usr/spool/uucp:/usr/lib/uucp/uucico
 
 
 
ASG: *: 6: 6: The owner of assignable devices :/:
 
 
 
STEVE: *: 203: 100:/users/STEVE:/usr/bin/KSh
 
 
 
Other: *: 4: 4: needed by secure program :/:
 
 
 
$ Cut-D:-F1/etc/passwd extract Field 1
 
 
 
Root
 
 
 
Cron
 
 
 
Bin
 
 
 
Uucp
 
 
ASG
 
 
 
Steve
 
 
 
Other
 
 
 
$ Cut-D:-F1, 6/etc/passwd extract fields 1 and 6
 
 
 
Root :/
 
 
 
Cron :/
 
 
 
Bin :/
 
 
 
Uucp:/usr/spool/uucp
 
 
 
ASG :/
 
 
 
STEVE:/users/Steve
 
 
Other :/
 
 
 
$

 

Grep

Grep pattern filesSearch mode string

*,? Can be applied to mode strings and file names

Example of a regular expression:

Grep '[A-Z]' list

Lines fromListContaining a capital letter

Grep '[0-9] 'data Lines fromDataContaining a number
Grep '[A-Z]... [0-9] 'list

Lines fromListContaining five-character patterns that start with a capital letter and end with a digit

Grep '\. PIC $ 'filelist Lines fromFilelistThat end in. PIC

Grep-ICase Insensitive

Grep-VFind the row of the unmatched pattern string

Grep-lOnly list files containing mode strings

Grep-nAn additional matched row number is provided.

Sort

Sort

Sort-u remove duplicate items

Sort-r reverse sorting

Sort-O redirection to the file sort names-O sorted_names is equivalent to sort names-o> sorted_names

Sort-N arithmetic sorting, not character sorting

Sort + 1n skips 1st fields and performs arithmetic sorting

Sort-T specifies the delimiter to separate fields. Generally, sort + 1n is separated by space or tab by default.

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.