所以如果文件是
abcd // no remove because it's has alphabets
a-c // no remove because it has numbers
1-1 // remove because it has both number and hyphen
a-1 // no remove because it contains alphabet
11 // no remove because it has no hypen
仅删除“1-1”,因为它只包含数字和“ - ”
答案 0 :(得分:1)
尝试:
grep -vE "^([0-9]*\\-[0-9]+)|([0-9]+\\-[0-9]*)$" input.txt
或者如果您的输入不包含只有" - "你可以简单地使用的角色:
grep -vE "^[0-9]*\\-[0-9]*$" input.txt
答案 1 :(得分:1)
试试这个。这是使用perl和regex。
perl -lne '{if($_!~/\d{1,}-\d{1,}/){print $_;}}' input_file