[NTLUG:Discuss] Quickest way to edit file?

David Stanaway david at stanaway.net
Mon Jul 23 15:33:35 CDT 2007


Bah

the fastest is surely

sed -i /bad at address/d file



MadHat Unspecific wrote:
> 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
>
>   




More information about the Discuss mailing list