grep 仅显示匹配部分

默认情况下grep显示对应的整行,如果要做统计的话,需要sed去除不要的部分, 但grep提供了仅显示需要的部分, 使sed脚本更简单.


选项是-o


如找出jdbc中报表不存在的有多少哪些

grep -o "Table .* doesn't exist" xxx.log | sed -e "s/Table '\(.*\)' doesn't exist/\1/" | sort | uniq > lost_table.txt

如果有多个log, 可以加上-h选项

grep -o "Table .* doesn't exist" *.log* | sed -e "s/Table '\(.*\)' doesn't exist/\1/" | sort | uniq > lost_table.txt

你可能感兴趣的:(bash)