in reply to grep or perl

Update: It was my mistake :-))
cd /your/old/dir/
cp `grep -rl 'NNNN'` * /your/new/dir/
cp `grep -rl 'NNNN' *` /your/new/dir/
      
--------------------------------
SV* sv_bless(SV* sv, HV* stash);

Replies are listed 'Best First'.
Re: Re: grep or perl
by TVSET (Chaplain) on Jun 04, 2003 at 14:44 UTC
    You have a small typo. I guess you meant this:

    cd /your/old/dir/ cp `grep -rl 'NNNN' *` /your/new/dir/

    If one needs another solution for any reason, there is always a for loop:

    for file in `grep -rl 'NNNN' *` ; do cp $file dstdir/ ; done

    Also, this will find files that contain match. Use "-L" in grep, if you want those files which do not contain match.

    Leonid Mamtchenkov aka TVSET

Re: Re: grep or perl
by Anonymous Monk on Jun 04, 2003 at 12:54 UTC
    I used grep -rL instead of l ..... because I want to copy files that do not contain the previously mentioned string. But the number of files seems to stop this command from working. Does anyone have more suggestions?

      This is why another poster suggested xargs. xargs reads arguments from standard input, and executes a command with arguments. It chunks the input and repeats the command as required, to avoid going over any command-line-length limits of the shell.

      Instead of just (xargs --help), try (man xargs) for some examples (search for EXAMPLES) and details.

      --
      [ e d @ h a l l e y . c c ]

      That is why broquaint used xargs. It runs a command for each argument (whitespace separated) it gets on its STDIN. Try reading man xargs

      --

      flounder

      Well, you are right about L but why doesn't grep -rL work? Maybe I didn't understand clearly but I checked this command and all are working correctly.
            
      --------------------------------
      SV* sv_bless(SV* sv, HV* stash);