grep和sed命令

rep -Po '.*(?=a.*ll)' log
57394 calls processed
变成
57394 c

grep -Po '.*(?=3.*ll)' log
57394 calls processed
变成
57
具体原理有待了解

echo aa,123,2345,24567,bb | grep -Po '(\d{2})' 2位数切片丢掉不足其它显示,忽略

字母
12
23
45
24
56
echo aa,2,123,2345,24567,bb | grep -Po '(\d{2,})'2位数以上切片
123
2345
24567
echo aa。2.123。2345。24567。bb | grep -Po '(\d{2,})'效果一样
echo aa。2F123S2345T24567,bb | grep -Po '(\d{2,})'效果一样

grep -P '\d{1,}'file 效果等于 grep '[[:digit:]]' file


sed 's/\(love\)able/\1rs/g' file
file内容:loveable 显示变为 lovers 原file内容不变,要改变file内容只需
sed -i 's/\(love\)able/\1rs/g' file

sed -i '2d' file
file内容
n1 => n1
n2 => n3
n3 =>


你可能感兴趣的:(grep,sed)