Dhaval Chauhan
Dhaval Chauhan

Reputation: 9473

How to remove line if it contains "-" and numbers [0-9]

So if the file is

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

Only remove "1-1" because it contains only numbers and "-"

Upvotes: 0

Views: 81

Answers (2)

msabhi
msabhi

Reputation: 81

Try this. This is using perl and regex.

perl -lne '{if($_!~/\d{1,}-\d{1,}/){print $_;}}' input_file

Upvotes: 1

Nima Ghotbi
Nima Ghotbi

Reputation: 671

try:

grep -vE "^([0-9]*\\-[0-9]+)|([0-9]+\\-[0-9]*)$" input.txt

or if your input doesn`t contain a line with just "-" character you can simply use:

grep -vE "^[0-9]*\\-[0-9]*$" input.txt

Upvotes: 1

Related Questions