0

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?

3
  • 1
    Welcome! Could you post a sample of the file? Commented Apr 24, 2020 at 6:51
  • if you could provide a sample it would be better, but anyway maybe just simple grep ".co.uk" file > file2 can do the job.
    – binarysta
    Commented Apr 24, 2020 at 6:52
  • @binarysta, you have to either add -F or escape the dots, see the answers.
    – pLumo
    Commented Apr 24, 2020 at 7:10

2 Answers 2

4

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
0
3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .