Doppleganger Software <doppsoft@TZC.COM> writes: > Also, is there a UNIX way to to a multi-file find & replace without > writing a complex script? I want to do a complete find & replace of the > IS_AFFECTED with the AFF_FLAGGED, but it occurs is so many places, it is > unfeasible to do so. Also, I have IS_AFFECTED2, IS_AFFECTED3, & > IS_AFFECTED4, so I want to change them all, without too much work. I can > do so in BBedit, if I download all the code, then re-upload it, but > that's an awful lot of work and transfer time (I figure 20 minutes at my > speed modem) and also if I need to do it again, I want to know how :) There are several ways. Probably the easiest for one-time changes like this would be to use Emacs. Type "emacs" in the directory of your code. Then type M-! (quick emacs lesson: C-<anything> means hold control while pressing the given key... M-<anything> means hold alt. C-M-<anything> obviously means both... so in this case hold alt and hit ! (which means hold alt and shift and hit 1)). So... M-! will result in a prompt to execute. Type "etags *.c *.h" and it should complete with no output. Next type M-x then type in "tags-query-replace" and it will ask you for a string to replace then what to replace it with. A more general way is to use perl or sed. Here's a sed script I sometimes use. Call it with the first parameter being the script to execute on all the c and h files in the current directory. In this case you would use a single file containing the line "s/IS_AFFECTED/AFF_FLAGGED/g". Sed is a great tool, as is perl. Of course IMO Emacs is about the best tool there is for coding, but I'm biased.. --sedsrc-- #!/bin/sh for i in *.c *.h do sed -f $1 $i > $i.tmp echo $i mv -f $i.tmp $i done --end-- -- James Turner turnerjh@xtn.net http://www.vuse.vanderbilt.edu/~turnerjh/ +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST