[Tfug] Quick command line question...

brandon brandons.daemon at gmail.com
Wed Mar 10 09:25:13 MST 2010


On Wed, Mar 10, 2010 at 8:55 AM, brandon <brandons.daemon at gmail.com> wrote:

> On Wed, Mar 10, 2010 at 8:49 AM, brandon <brandons.daemon at gmail.com>wrote:
>
>> On Wed, Mar 10, 2010 at 8:41 AM, Jim March <1.jim.march at gmail.com> wrote:
>>
>>> Folks,
>>>
>>> Say I've got a bunch of text files in a directory...all ending with
>>> .TXT...a dozen or so.
>>>
>>> I know that in some, a particular word isn't spelled right - say,
>>> "regurjitation".  I want to do a command to search for that and
>>> replace it with "regurgitation" across all files where the bad one is
>>> found, and save all files to their original names.
>>>
>>> Any help appreciated :).
>>>
>>> Jim
>>>
>>> _______________________________________________
>>> Tucson Free Unix Group - tfug at tfug.org
>>> Subscription Options:
>>> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>>
>>
>> Hi Jim-
>> Not sure what distro you are using but there is a nice perl utility
>> 'rename' that is on most.
>>
>> man rename
>>
>> Then you can do something like this to get an idea of what would happen.
>> rename -n 's/regurjitation/regurgitation/' *.TXT
>>
>> Thanks
>> -Brandon
>>
>>
> Oh I think I didn't read that =) That will rename the files and not the
> words in the files!
>
>
>
For multiple files I prefer to do two steps. Do a replace and write the file
to a  temporary file. Once I have reviewed the changes and know that I
haven't done anything horrible. I move them back into place.

 for i in *.TXT; do sed 's/testing/test/g' $i> `basename $i`.TMP; done

review all *.TMP files
and if ok

for i in *.TMP; do mv $i `basename $i .TMP`; done

Thanks
-Brandon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tfug.org/pipermail/tfug_tfug.org/attachments/20100310/3b2996c3/attachment-0002.html>


More information about the tfug mailing list