Basic shell command

Source: Internet
Author: User

###### #shell脚本命令 #######
###### #1. grep command #######
grep keyword File | directory # #在文件或目录中查找含有关键字的行

Grep-i # #忽略大小写
-N # #显示关键字所在的行
-C # #显示过滤结果的个数
-V # #反向过滤
-e "keyword 1| keyword 2" # #过滤多个关键字
-R Directory # #在目录中查找含有关键字的文件
Note: ^ keyword # #以关键字开头
Keyword $ # #以关键字结尾

###### #2. Cut command ########
Cut # #截取字符
cut-d Delimiter # #指定分隔符
-F 1, 7 # #显示指定列
-C 1-4 # #显示指定的字符

###### #3. Sort command ##########
Sort # #排序
Sort-n # #纯数字排序
-U # #去冗余
|UNIQ-C # #去除冗余并统计冗余次数
-T # #指定分隔符
-K # #指定列
####### #4. Uniq command #########
The Uniq command needs to be used with the sort command
Sort file |uniq-c # #去除冗余并统计冗余次数
-D # #显示冗余行
-U # #显示唯一行

####### #5. sed command #########
sed ' s/original character/replacement character/g ' file
sed-e ' policy 1 '-e ' policy 2 ' file
Sed-i file   &n bsp;         # #把转换后的内容输入到指定文件
Sed ' 3,5s/original character/replacement character/g '     # #3-5 line replace
sed xd                           # #屏蔽指定行
Sed xp                            # #复制指定行
Sed-n xp                        # #只显示指定行
######## #6. TR command ##########
tr ' A-Z ' A-Z ' < file


##### #for Do-Done statements #####
For i in {1..8}; do echo $i; Done
# #表示定义一个数组 {1..8}, given a variable I, outputs the value of I.
###### #7. awk######
Awk is a powerful text analysis tool that, compared to grep lookup, sed editing, is particularly powerful when it analyzes and generates reports on data.
Awk is to read the file one line at a time, using a space as the default delimiter to slice each row, and the part of the cut to perform various analytical processing.
The awk command uses a set of user-supplied commands to compare a set of files to a user-supplied extended regular expression, one line at a time, and then perform actions on any row that matches the extended regular expression
awk parameter ' script ' file
-F FS # #指定文件输入的分隔符 FS refers to a string or a regular expression
-F Scripfile # #从脚本文件中读取awk命令



Basic shell command

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.