The character processing of Linux system learning

Source: Internet
Author: User

Pipeline

Pipelines are a very frequent communication mechanism, and we can use the pipe symbol "|" To connect the process,
Connected by pipelines The order process can run automatically, as with a data flow, so the pipeline behaves as a method of input and output redirection,
It can be the output of a command as the input of the next command, two commands only need to connect a pipe symbol

Search for text using grep

grep [-ivnc] ' needs matching characters ' file name #-i case-insensitive #-c statistics contains matching rows #-n output line number #-v reverse match
Example:
[email protected] ~]# cat Test.txt
The cat ' s name is Tom,what's the mouse ' s name?
The mouse ' s NAME is Jerry
They is good friends
[[email protected] ~]# grep ' name ' test.txt//search for a sentence containing ' name '
The cat ' s name is Tom,what's the mouse ' s name?
[[email protected] ~]# grep-i ' name ' test.txt//Search for sentences containing ' name ', ignoring case
The cat ' s name is Tom,what's the mouse ' s name?
The mouse ' s NAME is Jerry
[[email protected] ~]# grep-c ' name ' test.txt//the number of sentences with ' name '
1
[[email protected] ~]# grep-ci ' name ' test.txt//the sentence with ' name ' has how many, case can be ignored
2
[[email protected] ~]# grep-v ' name ' test.txt//search for a sentence that does not contain ' name '
The mouse ' s NAME is Jerry
They is good friends
[[email protected] ~]# grep-vi ' name ' test.txt//search for sentences without ' name ', uppercase name is also filtered out
They is good friends
[email protected] ~]# cat Test.txt
The cat ' s name is Tom,what's the mouse ' s name?
The mouse ' s NAME is Jerry
They is good friends
[email protected] ~]# Cat Test.txt | Grep-vi ' name '? The above commands can be rewritten with pipe characters, such as the previous command, which means the same thing.
They is good friends

Sort by using sort

Sort [-NTKR] file name #-n take numeric sort #-t Specify delimiter #-k specify column #-r reverse sort [[email protected] ~]# cat Sort.txtb:3c:2a:4e:5d:1f:11[[email Protect Ed] ~]# Cat Sort.txt | Sort//alphabetical order A:4b:3c:2d:1e:5f:11[[email protected] ~]# cat Sort.txt | Sort-r//Reverse alphabetical order F:11e:5d:1c:2b:3a:4[[email protected] ~]# cat Sort.txt | Sort-t ":"-K 2-nd:1c:2b:3a:4e:5f:11

Use Uniq to remove duplicate content

Uniq [-ic]#-i ignore case #-c compute duplicates [[email protected] ~]# Cat Uniq.txt | Sort | Uniq//What needs to be explained is that the Uniq command generally needs to be used with sort, that is, to sort the file using sort first, and then use Uniq to delete the duplicate content. It is not effective to add uniq without the sort alone. 123ABC Supplemental NOTE: [[email protected] ~]# Cat Uniq.txt | Uniqabc123abc123[[email protected] ~]# cat Uniq.txt | Sort | UNIQ-C//using the-c parameter prints the number of row repeats in front of each line      2 123

Use Cutt to intercept text, use TR to do text conversion, use paste to do text merge (there is also a file split with split do, here no longer say, I do not know what it really is)

Cut-f Specify column-d ' delimiter '

[Email protected] ~]# CAT/ETC/PASSWD | Cut-f1-d ': ' Rootbindaemonadmin


The TR command is relatively simple and its main function is to convert or delete text
[Email protected] ~]# CAT/ETC/PASSWD | TR ' [A-z] ' [A-z] '
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin

The role of paste is to merge files into rows, using tab-separated
[email protected] ~]# cat A.txt
A b C
[email protected] ~]# cat B.txt
A b C
[email protected] ~]# paste A.txt b.txt
A b c a B C





The character processing of Linux system learning

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.