我都差点想倒过来求伊甸园主给俺搭把手,那爱太阳肯定是写regular expression搜索命令的高手,这爱太阳要是伸一小手,俺十天的活一天就能搞定。后来一想,俺不能给党添麻烦。作者: thesunlover 时间: 2007-5-30 14:34 海雨,什么搜索?讲出来听听?如果能做一定做。即使俺不行,没准这里有高手。作者: searain 时间: 2007-5-30 14:43 OK. for example, this is just one of these search.
Search all the files on the server. replace "announcements_id" with "selected_announcements_id" if "announcements_id" appears in the following strings.
Well, I am on my last day of these kind codes clean up now. So no need to waste brain cells on it now. But if it is just a piece of cake for you, well just for the fun of it.作者: thesunlover 时间: 2007-5-30 15:37 I wrote a script a few months ago which is to replace words for all files in a directory tree (See below). You can also google some existing scripts to avoid recreating the wheel. This is a good one:
find . -type f | egrep -i '(htm|php|txt)' | grep -v reserved | while read i
do
sed "s/$w1/$w2/g" $i | sed "s/$w2/$w3/g" | sed "s/$c1/$c2/g" | sed "s/$c2/$c3/g" | sed "s/$s1/$s2/g" > $i.tmp && mv $i.tmp $i
egrep -il "($c1|$s1)" $i
done作者: thesunlover 时间: 2007-5-30 15:44 To get rid of all entried starting with announcements_id:
grep -v ^announcements_id
Google: replacement script, script to replace words, etc.作者: searain 时间: 2007-5-30 15:57 Thanks! I used to just use free regular expression scripts for the popular tasks such as email validation etc.
When I began my code cleaning works. I thought it would be 2 or 3 days work. I use the slow but safe way, search for the above strings one by one, and manually confirm the replace. Now it is the 10th day and I am kicking myself why not regular expression. If I use 2 days to read the codes, found all the replace and not replace situations. Use 1 day to find free scripts and modify for my purposes. I can do it in 3 days instead of 10 days.
It is going to be too late to teach this old dog new tricks, but I have no choice, when I finish my next round developing tasks, I will have to learn more about regular expression, xml, ajax etc.