
如何從文件中僅刪除 0,1,2,3,4,5,6,7,8,9 個字元長的數字?我的意思是與該模式匹配的線條。
可移動線範例:
cat input.txt
1
123423113
8372
8472323
不應刪除的行範例:
cat input.txt
1a
1245d45
8565438753
b39592
3827495Hx
答案1
使用sed
:
sed -i.bak -e '/^[0-9]\{1,9\}$/d' file
使用perl
:
perl -i.bak -nle 'print unless /^[0-9]{1,9}$/' file
答案2
perl -i.bak -nle 'print unless /^[0-9]{0,9}$/' file
您也要求刪除零長度數字(即空白行)。