Reputation: 865
I have a text file that looks like this:
0,16777215
16807368,16807368
621357328,621357328
621357403,621357403
1380962773,1380962773
1768589474,1768589474
Is there a way to use sed
to make sure that each line ONLY has numbers and one comma? If a line is missing the comma, contains letters, is blank, has spaces, etc. - then I want to delete it.
Upvotes: 0
Views: 187
Reputation: 5298
With sed
:
sed -nr '/^[0-9]+,[0-9]+$/p' File
To edit the file in-place:
sed -nri '/^[0-9]+,[0-9]+$/p' File
A portable solution:
sed -nE '/^[0-9]+,[0-9]+$/p' File
Upvotes: 2
Reputation: 21492
sed -e '/^[0-9]\+,[0-9]\+$/ !d' file
The address is a regular expression. If the line does not match the regular expression, the d
(delete) command is applied. (The exclamation mark (!
) inverts the condition.)
Upvotes: 0