Reputation: 479
I have a text file with dates in this format: 27/8/2019
I would like to remove all lines except for those that contain 27/8/2019
If I use sed, that would be:
sed -i '/pattern/!d' file.txt
The problem is that when I have a pattern with '/
', I have the next error:
sed: -e expression #1, char 5: unknown command: `8'
Upvotes: 1
Views: 1957
Reputation: 17488
It's easier to use grep
in this case.
grep '27/8/2019' file.txt
Upvotes: 0
Reputation: 41460
Using awk
awk '/27\/8\/2019/' file.txt
If date is just a sample, use this to keep all date line:
awk '/[0-9]+\/[0-9]+\/[0-9]+/' file.txt
To update file inline with awk
awk '-your code-' file.txt > tmp && mv tmp file.txt
Upvotes: 0