6.7.2. Using comments (prefixed by the '#' sign)
Most versions of sed permit comments to appear in sed scripts only
on the first line of the script. Comments on line 2 or thereafter
are not recognized and will generate an error like "unrecognized
command" or "command [bad-line-here] has trailing garbage".
GNU sed, HHsed, sedmod, and HP-UX sed permit comments to appear on
any line of the script, except after labels and branching commands
(b,t), provided that a semicolon (;) occurs after the command
itself. This syntax makes sed similar to awk and perl, which use a
similar commenting structure in their scripts. Thus,
# GNU style sed script
$!N; # except for last line, get next line
s/^\([0-9]\{5\}\).*\n\1.*//; # if first 5 digits of each line
# match, delete BOTH lines.
t skip
P; # print 1st line only if no match
:skip
D; # delete 1st line of pattern space and loop
#---end of script---
is a valid script for GNU-based versions of sed, but is
unrecognized for most other versions of sed.
Finally, if the first two characters in a disk file script are
"#n", the output is suppressed, exactly as if -n were entered on
the command line. This is true for the following versions of sed:
- ssed v3.57 and above
- gsed
- HHsed v1.5
- sed v1.6
This syntax is not recognized by these versions of sed:
- ssed v3.45 to v3.50 (other versions untested)
- sedmod v1.0