Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Remove lines from a file based on a second file

by Anonymous Monk
on Oct 14, 2011 at 15:50 UTC ( [id://931544]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I've got two files - a long CSV file, and another long file with a list of values in it. I need to remove from the long CSV file all of the entries where field 2 in the CSV matches any value in the long file. I can see loading the two into perl arrays, but I'm hoping there is a way to do this without two nested loops inside the perl script. Any suggestions? Thanks
  • Comment on Remove lines from a file based on a second file

Replies are listed 'Best First'.
Re: Remove lines from a file based on a second file
by AR (Friar) on Oct 14, 2011 at 16:36 UTC

    Could you adapt the advice given in this node?

Re: Remove lines from a file based on a second file
by wwe (Friar) on Oct 17, 2011 at 08:43 UTC
    In general first read the file with values into a hash using values as hash keys then loop over the csv file and skip every value which matches a key in a hash. We'll be happy to help you when you show us your code.
Re: Remove lines from a file based on a second file
by Anonymous Monk on Oct 15, 2011 at 06:29 UTC
    load files with DBD::CSV, issue appropriate sql query, be done in time for dinner

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://931544]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-18 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found