Let's look at a script that shows how the print command might be used for debugging purposes. It is used to show what the line looked like before you made any changes.
#n Print line before and after changes. /^\.Ah/{ p s/"//g s/^\.Ah //p }
Note that the print flag is supplied to the substitute command. The substitute command's print flag differs from the print command in that it is conditional upon a successful substitution.
Here's a sample run of the above script:
$ sed -f sed.debug ch05 .Ah "Comment" Comment .Ah "Substitution" Substitution .Ah "Delete" Delete .Ah "Append, Insert and Change" Append, Insert and Change .Ah "List" List
Each affected line is printed twice.
We'll see additional examples of the print command in the next chapter. See also the multiline print command (P) in the next chapter.
Copyright © 2003 O'Reilly & Associates. All rights reserved.