how to do file1-file2?

Discussion in 'Perl Misc' started by robertchen117@gmail.com, Mar 13, 2007.

  1. Guest

    my files contains all lines of host names, also file2.

    I want a shell could have the result : remove all the line in file1,
    if the line is in the file2.

    Please help. Thanks.
    , Mar 13, 2007
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth "" <>:
    > my files contains all lines of host names, also file2.
    >
    > I want a shell could have the result : remove all the line in file1,
    > if the line is in the file2.
    >
    > Please help. Thanks.


    If you install the File::Slurp module, the following will do what you
    want:

    perl -MFile::Slurp -ne'
    BEGIN{ @rej{read_file "file2"} = (); }
    print unless exists $rej{$_};
    ' file1

    To edit file1 in place use the -i switch (see perldoc perlrun).

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    'Alcestis') [ flame, and falls out of sight. ]
    Ben Morrow, Mar 13, 2007
    #2
    1. Advertising

  3. <> wrote:
    > my files contains all lines of host names, also file2.
    >
    > I want a shell could have the result : remove all the line in file1,
    > if the line is in the file2.



    grep -v -f file2 file1 >newfile


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Mar 13, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Pet
    Replies:
    0
    Views:
    1,384
    Alex Pet
    Jan 20, 2004
  2. Replies:
    4
    Views:
    466
  3. Christopher M. Lusardi
    Replies:
    1
    Views:
    352
    Michael Mair
    Nov 16, 2004
  4. Christopher M. Lusardi

    How To Reduce Number Files by Putting file1.c and file2.C Together

    Christopher M. Lusardi, Nov 16, 2004, in forum: C Programming
    Replies:
    1
    Views:
    317
    Michael Mair
    Nov 16, 2004
Loading...

Share This Page