sed -i "s/hahaha/hehehe" myfile.txt
This replaces all instances of the string "hahaha" with the string "hehehe". How useful is this?
Well, if I need to fit many webpages into a small webserver, you can use sed to delete all the irrelevant tags (like those that inserted by FrontPage) or comments to squeeze the files into smnaller sizes. Or if you need to add some html into many files that contain the same structured data, this comes in handy as well. For example, this shell script adds a new string tag5 after tag4 for all the htm files in the current directory:
myfiles=`ls|grep "htm$"`; for xfile in $myfiles; do sed -i "s/tag4/tag4;tag5" $xfile; done;
Most people would prefer to use Server Side Includes to avoid such a maintenance nightmare from appearing in the first place, but if you are not allowed to use that then perhaps this is an alternative.
I've always wondered how Windows knew which interface to use in a PC with multiple adapters. Found out you can bind certain protocols to specific network adapters such that it becomes the default interface to be used.
So it's not too bad, at least I'm learning something while doing some mundane jobs like updating catalgoues or dis/assembling PCs.
No comments:
Post a Comment