[NTLUG:Discuss] Quickest way to edit file?
    MadHat Unspecific 
    madhat at unspecific.com
       
    Mon Jul 23 11:19:09 CDT 2007
    
    
  
Lance Simmons wrote:
> On 7/23/07, Fred James <fredjame at fredjame.cnc.net> wrote:
> 
>> For a single address ...
>> grep -v regex original_file > new_file
> 
> I've done something similar with sed a few times, but it still leaves
> the extra step of renaming new_file back to original_file.
Perl
  perl -pi -e 's/email\@address\n//' file
Not saying it is easier than vi, but it is a way of doing it in one 
command without haveing to rename files and such.
Details for those who care:
perl - the perl command
  -pi - use the file specified as if it were called in a while loop
        (see perlrun for details)
  -e  - execute the following code
   code is a simple regex
  s - substitute
    so if you have s/this/that/ would substitute 'this' with 'that'
    since we are dealing with an email and a @ has a special meaning in 
perl, we escape it with the \
   the \n at the end is a new line, so you would have to have the full 
address to do this properly.
   the fact that there is nothing in the second section of the 
substitution mean we don't replace it with anything, or we replace it 
with nothing, or what ever I mean...
   yes there are other ways of doing this with the same command just 
changing the perl code.
I need more caffeine
-- 
MadHat (at) Unspecific.com, C²ISSP
E786 7B30 7534 DCC2 94D5  91DE E922 0B21 9DDC 3E98
gpg --keyserver wwwkeys.us.pgp.net --recv-keys 9DDC3E98
    
    
More information about the Discuss
mailing list