I have text file with 25 millions of lines (a list of domain names).
How can I extract domains that contain .co.uk
to another txt file?
Given a file like:
foo.co.uk
bar.co.uk
baz.foo.bar
use the command:
grep "\.co\.uk$" file
Output:
foo.co.uk
bar.co.uk
Try this:
grep -F '.co.uk' file > filtered_file
-F
lets grep
search for a fixed string instead of a pattern which makes it a lot faster, especially given your 25 million lines. Then, you also don't need to escape the dots, which are special characters for a pattern.
Note, that this will also find lines like example.co.uk.com
or example.co.uk/index.html
. If you want the .co.uk
always in the end, go with this answer.
grep ".co.uk" file > file2
can do the job.-F
or escape the dots, see the answers.