Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I executed a search with grep, but it doesn't work like I expected it to. I have the following lines in a file:

blacklists/redirector/domains:needyoutube.com
lacklists/redirector/domains:openyoutube.com
blacklists/redirector/domains:proxy-youtube.com
blacklists/redirector/domains:proxytoyoutube.com
blacklists/redirector/domains:streamyoutube.com
blacklists/redirector/domains:unblockyoutube.com

When I run:

grep ':youtube.com'

I get no results. The following works:

grep 'youtube.com'

How can I escape the colon (:)? Backslash (grep '\:youtube.com') doesn't work. I use RHEL 5, grep (GNU grep) 2.5.1.

Update: I forgot the entries I wanted to grep, these exist also:

./blacklists/movies/domains:youtube.com
./blacklists/movies/domains:youtube.com.br

I want to just get the fields that contain the exact domain name. So I want to get the blacklists linked to youtube.com, so I use ":youtube.com".

From the list above (youtube.com, youtube.com.br), I only should get youtube.com, but I don't get anything.

I wasn't clear enough, sorry.

share|improve this question

migrated from serverfault.com Nov 16 '11 at 15:56

This question came from our site for system and network administrators.

2 Answers 2

up vote 1 down vote accepted

Looks like "blacklists/redirector/domains" is actually a filename, not part of the file's content. grep ':youtube.com' works just fine:

% cat test.txt
./blacklists/movies/domains:youtube.com
./blacklists/movies/domains:youtube.com.br
blacklists/redirector/domains:needyoutube.com
lacklists/redirector/domains:openyoutube.com
blacklists/redirector/domains:proxy-youtube.com
blacklists/redirector/domains:proxytoyoutube.com
blacklists/redirector/domains:streamyoutube.com
blacklists/redirector/domains:unblockyoutube.com
% grep ':youtube.com' test.txt
./blacklists/movies/domains:youtube.com
./blacklists/movies/domains:youtube.com.br

If you want to recursively find lines that starts with "youtube.com" use grep -R '^youtube\.com' path/to/dir

share|improve this answer
    
Hi, I work with the blacklist database on shallalist.de. I had: find . -type f ( ! -name "*.db" ) | xargs grep ':youtube.com' Here the grep doesn't work, but as you stated, grep ':youtube.com' test.txt works fine! To get all blacklists where a domain exists, I now use: grep -R '^youtube\.com$' blacklists/*/domains Thanks! –  user74952 Nov 17 '11 at 11:29

Grep is doing all right. That file does not contain any lines with ":youtube.com".

If you want to match all that lines with : you could use

grep ":.*youtube\.com"

UPD:

As you've update your question, I need try to answering second part.

From the list above (youtube.com, youtube.com.br), I only should get youtube.com, but I don't get anything.

Your grep ':youtube.com' actually did what you need. And if it's a paths -R option helps you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.