Find the answer to your Linux question:
Results 1 to 4 of 4
Hello all, I have a perl question. I need to remove the lines from 1 file that have a string matching a line on a different file, I could write ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    9

    Perl Search/Replace between 2 huge files


    Hello all,

    I have a perl question. I need to remove the lines from 1 file that have a string matching a line on a different file, I could write a script with sed or grep, but one file is 200 mb and the other one is 6 mb... just imagine.

    Here is the example:

    200mbfile:
    key1X,fild2,fild3,fild4,fild5
    key1C,fild2,fild3,fild4,fild5
    key1V,fild2,fild3,fild4,fild5
    key1B,fild2,fild3,fild4,fild5
    key1N,fild2,fild3,fild4,fild5

    6mbfile:
    keyC
    keyB

    Having this said... I need to create a new file with data from 200mbfile that is not key'd on the 6mb file... example:
    key1X,fild2,fild3,fild4,fild5
    key1V,fild2,fild3,fild4,fild5
    key1N,fild2,fild3,fild4,fild5

    Any Ideas? I was trying to do a foreach loop, but I was sugested to use hashes instead, but still, cant figure out how to do this effectively, any help is appreciated!

    Regards,
    OCON

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,304
    Hi.
    Quote Originally Posted by ocon View Post
    ...
    200mbfile:
    key1X,fild2,fild3,fild4,fild5
    key1C,fild2,fild3,fild4,fild5
    key1V,fild2,fild3,fild4,fild5
    key1B,fild2,fild3,fild4,fild5
    key1N,fild2,fild3,fild4,fild5

    6mbfile:
    keyC
    keyB

    Having this said... I need to create a new file with data from 200mbfile that is not key'd on the 6mb file... example:
    key1X,fild2,fild3,fild4,fild5
    key1V,fild2,fild3,fild4,fild5
    key1N,fild2,fild3,fild4,fild5

    ...
    How is the matching supposed to be done? You have apparently done something with, say keyC, so that the line
    Code:
    key1C,fild2,fild3,fild4,fild5
    is filtered out. However, there is an additional character, "1" between "key" and "C" ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    May 2009
    Posts
    9
    Hello!

    I was wondering why I didn't got any reply before... it was a typo... well things were more complicated but I am just about to figure it out, just having some issues with a regexp, but I am almost done.

    Thank you for pointing that out; and of course, for replying!
    Ocon

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    regular expression you say? this tool has saved me so much time. i recommend it for all.

    RegExr: Online Regular Expression Testing Tool
    linux user # 503963

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •