sed & awk

sed & awkSearch this book
Previous: 4.4 Four Types of sed ScriptsChapter 4
Writing sed Scripts
Next: 5. Basic sed Commands
 

4.5 Getting to the PromiSed Land

You have now seen four different types of sed scripts, as well as how they are embedded inside shell scripts to create easy-to-use applications. More and more, as you work with sed, you will develop methods for creating and testing sed scripts. You will come to rely upon these methods and gain confidence that you know what your script is doing and why.

Here are a few tips:

  1. Know Thy Input! Carefully examine your input file, using grep, before designing your script.

  2. Sample Before Buying. Start with a small sample of occurrences in a test file. Run your script on the sample and make sure the script is working. Remember, it's just as important to make sure the script doesn't work where you don't want it to. Then increase the size of the sample. Try to increase the complexity of the input.

  3. Think Before Doing. Work carefully, testing each command that you add to a script. Compare the output against the input file to see what has changed. Prove to yourself that your script is complete. Your script may work perfectly, based on your assumptions of what is in the input file, but your assumptions may be wrong.

  4. Be Pragmatic! Try to accomplish what you can with your sed script, but it doesn't have to do 100 percent of the job. If you encounter difficult situations, check and see how frequently they occur. Sometimes it's better to do a few remaining edits manually.

As you gain experience, add your own "scripting tips" to this list. You will also find that these tips apply equally well when working with awk.


Previous: 4.4 Four Types of sed Scriptssed & awkNext: 5. Basic sed Commands
4.4 Four Types of sed ScriptsBook Index5. Basic sed Commands

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System