Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: remove lines matching list of strings

by TomDLux (Vicar)
on Nov 08, 2012 at 21:51 UTC ( #1002996=note: print w/replies, xml ) Need Help??


in reply to remove lines matching list of strings

grep -v -F -f file2 file1

English translation: using the Unix grep command, search file1 for lines which do not match ( -v ) the fixed strings ( -F ) ( as opposed to regular expressions ) found in file2 ( -f file2 ).

There are versions of grep available for Windows. Mac OS has a Unix basis, so it already has it.

If you absolutely have to do it in Perl, I would use the lines from file2 as the keys of a hash, assigning the number 1 as a value. Then, as I read the other file, it's trivial to check whether it is present in the hash.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: remove lines matching list of strings
by rootcho (Pilgrim) on Nov 08, 2012 at 22:51 UTC
    Yes, I was thinking in the same line... if done in perl using hash seem to be better than building giant regex.
    Heh...didn't know about -F option.. will check it out
    thanks

      Neither did I, but I scanned through man grep to make sure I was doing things right. I did have a vague recollection there was an option to search for strings rather than regex ... it helps if you know to search for something.

      As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002996]
help
Chatterbox?
[Discipulus]: ah! so you mean if i need a static image i can use Twig, if on the fly better css selector and mody attrs (jquery?), rigth?
[LanX]: not sure what you guys are taking about, but a DOM manipulation in JS shouldn't be difficult
[Corion]: Discipulus: Yeah, that's what I would try (but so far, I can't even change the colors manually in the SVG, which is why I gave up ;) )
Discipulus bad sign..
[Discipulus]: italian doc says to modify somehow the initial SVG before using it with D3.js
[Discipulus]: LanX the fact is that my js ability is even poorer than my Perl one..
[LanX]: oh its negative? ;P

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2017-03-23 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.