Salvatore Di Fazio
Salvatore Di Fazio

Reputation:

Regex get lines that haven't a word

I have the following lines in a files:

a class="rss tip" rel="direct" title="Linq2Sql" href="http://feeds2.feedburner.com/pippo_ORM"></a>
a class="rss tip" title="ORM" href="http://feeds2.feedburner.com/pippo_ORM" rel="nofollow"></a>
a class="rss tip" rel="boh" title="Nhibernate" href="http://feeds2.feedburner.com/pippo_ORM"></a>
a class="rss tip" rel="direct" title="Linq2Sql" href="http://pippo.it/pippo_ORM"></a>
a class="rss tip" title="Linq2Sql" href="http://pippo.it/pippo_ORM"></a>
<a class="rss tip" title="direct" href="pippo"></a>

I need to get all the anchors that haven't the url "pippo.it" in href. I would like to remove the lines that contains the word rel="direct" from the result.

How can I do that?

I use RegexBuddy and I need to put the code on a .NET console program. I need to search the lines on the whole file.

Tnx

Upvotes: 1

Views: 228

Answers (3)

ghostdog74
ghostdog74

Reputation: 342373

awk '!/rel=\"direct\"/ && !/href.*pippo.it/s' file

Upvotes: 0

Draemon
Draemon

Reputation: 34711

grep -v 'href="[^"]*pippo.it\|rel="direct"' file.txt

Upvotes: 1

Paul Dixon
Paul Dixon

Reputation: 300855

Something like this should do it

grep -v "pippo.it" myfile.txt | grep -v "rel=\"direct\""

The -v inverts the match, so that lines without the pattern are output

Upvotes: 0

Related Questions