Grep
grep -E "^(root|yu)" /etc/passwd
grep -E "^(root|yu)\>" /etc/passwd # >表示仅仅匹配这俩个字母的开头
grep -v "root" /etc/passwd -n
grep --help # 查看帮助文档
grep -c "^yu" /etc/passwd # 统计
grep -m(2) "^yu" /etc/passwd # 仅匹配俩次
grep -l "yu" /etc/passwd /data/yu.txt # 判断文件之中是否有yu的字符串
grep -v "/bin/bash" /etc/passwd
grep -E "\>[0~9]{2,3}\>" /etc/passwd -o # 匹配俩位或者三位数字
grep "^[[:space:]].*" xxx.txt # 找出文件之中以空格开头的行
grep -E "^[[:space:]]+[^[:space:]]" xxx.txt
grep -i "^i" xxx.txt
grep -E "(i|I)" xxx.txt
grep "[iI]" xxx.txt
grep -E "^(yu|nobody|root)\>" xxx.txt
grep -E "[a-zA-Z]+\(\)" xxx.txt # 找出函数名的
grep -E "^([^:]+\>).*\1$" xxx.txt # 用户名和解释器相同的行
Sed
sed 's/root/xxx/(g)p' pwd.txt -n # g为全局替换,-n 和p连用
sed -n '1,10s/^bin/c/p' pwd.txt # 替换1到10行的内容
sed -n -e '1,10s/bin/c/p' -e 's/^m/M/p' pwd.txt # 多次操作文件
sed '5,$d' pwd.txt # 删除第4行之后的文件
sed '1,5d' pwd.txt # 删除前5行
sed '/root/,/^ftp/d' pwd.txt # 删除root~ftp的行
sed '/^[[:space:]]/#/gp' pwd.txt # 为文件中空白开头加上#
sed -e '/^[[:space:]]/#/g' -e 's/^$/#/g' pwd.txt
sed -e '/^#/d' -e '/^$/d' xxx.txt
sed '/^#/d;/^$/d' xxx.txt # 删除无用行
sed -r '1,3s/(^.)/@\1/' xxx.txt# 在文件的前三个字符转换
ifconfig ech0|sed '2p' -n|sed 's/^.*inet//'|sed 's/netmask.*//' pwd.txt # 取出IP地址
ifconfig ech0|sed '2s/^.*inet//;s/netmask.*//p' -n pwd.txt
ifconfig eth0 | sed -e..... # 多次编辑的操作
sed -r 's/^.*release[[:space]]([^.]+).**/\1/p' /etc/centos-release -n# 找出版本信息
Awk
awk -F ":" '$3>=1000{print $1 ,$(NF-1)}' /etc/passwd # 打印普通用户的信息
awk 'NR<6{print "#"$0}' xxx.txt # 在前五行加上注释#
awk -F "[ :]" '!/^$/{print $4}' xxx.txt # 取出分隔符不同的行信息
awk -F "[ :]" '/^Tom/{print $1,$4}' xxx.txt # 取出特定的信息
awk -F "[ :]" '$2~/^D/{print $2}' xxx.txt # ~表示模式里的正则匹配
awk -F "[ :]" '$3~/\[916\]/{print $3}' xxx.txt
awk -F "[ :]" '/^Mike/{print "$"$(NF-2), "$"$(NF-1),"$"$NF}' xxx.txt
awk -F "[ :]" '!/^$/{print $2,","$1}' xxx.txt
awk -F "[ :]" -v OFS="," '!/^$/{print $2,","$1}' xxx.txt
awk '/^$/{print $0}' xxx.txt