home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


sed & awk

sed & awkSearch this book
Previous: 5.1 About the Syntax of sed Commands Chapter 5
Basic sed Commands
Next: 5.3 Substitution
 

5.2 Comment

You can use a comment to document a script by describing its purpose. Starting in this chapter, our full script examples begin with a comment line. A comment line can appear as the first line of a script. In System V's version of sed, a comment is permitted only on the first line. In some versions, including sed running under SunOS 4.1.x and with GNU sed, you can place comments anywhere in the script, even on a line following a command. The examples in this book will follow the more restrictive case of System V sed, limiting comments to the first line of the script. However, the ability to use comments to document your script is valuable and you should make use of it if your version of sed permits it.

An octothorpe (#) must be the first character on the line. The syntax of a comment line is:

#[n]

The following example shows the first line of a script:

# wstar.sed: convert WordStar files

If necessary, the comment can be continued on multiple lines by ending the preceding line with a backslash.[2] For consistency, you might begin the continuation line with an # so that the line's purpose is obvious.

[2] This does not work with GNU sed (version 2.05), though.

If the next character following # is n , the script will not automatically produce output. It is equivalent to specifying the command-line option -n . The rest of the line following the n is treated as a comment. Under the POSIX standard, #n used this way must be the first two characters in the file.


Previous: 5.1 About the Syntax of sed Commands sed & awk Next: 5.3 Substitution
5.1 About the Syntax of sed Commands Book Index 5.3 Substitution

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