How to delete the lines from a file that do not contain dot?
I have a file that contains data including urls. But there are various lines which are not urls. How can I remove them using Ubuntu terminal commands?
Here is the Sample file for reference: Sample Data
com.blendtuts/S
°=
com.blengineering.www/:http
±=
I want to have the output :
com.blendtuts/S
com.blengineering.www/:http
The extra unwanted lines do not have any dot. Hence, I want to remove the lines without dots
One way with sed
sed '/\./!d' file
-
/\./
match literal dot (escaped with\
because otherwise.
matches any character) -
!d
delete everything except the matched pattern
If you want to edit the file in place, add -i
to the command after testing. (You can also add .bak
to the -i
flag sed -i.bak ...
to create a local backup of the file.)
sed -i '/\./!d' file
You could grep everything with a dot into a new file:
grep "\." file > newfile
That way you can save your old file.
Or keep the lines which contain a dot,
sed -ni.bak '/\./p' infile