sed & awksed & awkSearch this book

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.[28] For consistency, you might begin the continuation line with an # so that the line's purpose is obvious.

[28]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.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.