Ubuntu – How to delete the lines from a file that do not contain dot

command linetext processing

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

Best Answer

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