1.grep
Linux systems grep command is a powerful text search tool, it can use a regular expression search text, and the matching line printed. grep stands for Global Regular Expression Print, represents the global regular expression version, its usage rights for all users.
Tips: grep -E = egrep (extended regular expressions)
contents of the file:
## grep format ##
grep matching condition with files
grep root passwd 过滤root关键字
grep ^root passwd 以root开头
grep root$ passwd 以root结尾
grep -i root passwd 忽略大小写
grep -E "\<root" passwd root字符之前不能有字符
grep -E "root\>" passwd root字符之后不能有字符
Special symbols are extended regular expressions, it should be added -E parameter
roothaha disappeared.
grep -数字 显示过滤行以及上面几行和下面几行,A为文件名。
grep -n 显示匹配的行所在行号
grep -A 显示过滤行以及下面几行
grep -B 显示过滤行以及上面几行
grep -v 反向过滤
grep number of characters matching rules
^westos 以westos开头
westos$ 以westos结尾
w....s w开头s结尾中间4个任意字符
.....s s结尾前面5个任意字符
* 字符出现0到任意次
? 0到1次
+ 1到任意次
{n} n次
{m,n} m到n次
{0,n} 0-n次
{,n} 0-n次
{m,} 最少m次
(lee){2} lee字符串出现2次,lee要用括号括起来
2.sed
sed stream editor is an abbreviation of a stream editor, which processes a row contents. Handling, storing the row currently being processed in a temporary buffer, called a "model space" (pattern space), followed by treatment with the contents of the buffer sed command, the processing is completed, the contents of the buffer sent to the screen. Then the next line, which is repeated until the end of the file. File contents not changed, unless you use redirection to store the output. sed primarily used to automatically edit one or more files, the file operation is repeated to simplify the preparation of the conversion procedures.
Format:
sed 参数 命令 处理对象
## - b display line numbers, you can see only the contents of the fifth row are printed out.
sed 参数 处理对象 -f 处理规则文件
Handling of character
-n ## silent mode, only the line display process.
-e number of policy #.
p ## print, display print
sed -n 5p westos 显示第五行
sed -n 3,5p westos 显示3到5行
sed -ne "3p;5p" westos 显示3和5行
sed -ne 1,5p westos 1-5行
sed -ne '5,\$p' westos 5到最后以行
sed -n '/^#/p' fstab 显示以#开头的行
d delete
sed 5d westos 删除第五行
sed '/^#/d' fstab 把 # 开头的行删除
sed '/^UUID/!d' fstab 除了UUID以外的行都删除
sed -e '5,$d' westos 第五行删到最后
Add a
sed -e '\$a hello world' westos
sed -e '$a hello\nworld' westos \n换行
sed -e '/^#/a hello world' fstab
c Replace
sed -e '/^#/c hello world' fstab 以'#'开头的行都替换为 helloworld
sed '5c hello world' westos
w writes the rows that meet the specified file
sed '/^UUID/w westofile' westos 把westos中UUID开头的行写入westosfile中
i Insert
sed '5ihello westos' westos
Below is inserted into a, i is inserted to the upper
r consolidate file
sed '5r hah' westos 把hah文件的内容整合到westos文件第五行下面
sed character replacement
sed 's/: /###/g' westos 把全文的: 替换为'###'
sed 's/: /###/' westos 仅替换第一列
sed '1,5s/: /###/g' westos 1到5行
sed '1s/: /###/g' westos 替换第一行
sed '1s/: /###/g;5s/: /###/g' westos 替换第一行和第五行
sed '/lp/,/shutdown/s/: ###/g' westos 替换lp 和shutdown之间的:
sed 's/\//####/g' westos 替换/为###
sed 's@/@####@g' westos @的作用和/一样
sed 's@/@####@g' -i westos 把sed处理的内容保存到westos文件中
Visible content processing has been changed to the source file.
3.awk