[NTLUG:Discuss] Quickest way to edit file?
Daniel Hauck
daniel at yacg.com
Mon Jul 23 11:18:55 CDT 2007
> 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.
>
> For some reason, that extra step is the problem for me -- apparently
> it is too taxing for my feeble brain, because it slows me down every
> time. Did I come up with a unique name for new_file? Did I mess up
> when I renamed new_file back to original_file? Am I sure I don't now
> have _three_ files instead of one? That I didn't just delete
> everything by accident? Better check on that... and so on. By the time
> I get finished, I could have done the job with vi many times over:
>
> vi file /suitable-pattern-fragment dd :wq
>
> So maybe vi is the fastest way for someone as easily confused as me.
>
Ultimately, appending to a file doesn't require anything special, but
removing something from a file requires re-writing and I cannot see any
way around that short of writing nulls or spaces over the text which
would yield ugly results in my opinion.
In the end, you just need some simple shell scripts to manage the tasks
from a single command-line:
$ addmember -a <address> <address> ... / -f <filename>
$ delmember -a <address> <address> ... / -f <filename>
Where filename would contain a list and "address" would be one or more
specific addresses to add or delete.
then it would become easy to manage once established.
More information about the Discuss
mailing list