34.8 Newlines in a sed Replacement
The backslash ( Given the following input line where each item is separated by a tab: Column1 Column2 Column3 Column4 we can replace the second tab character on each line with a newline character:
Note that no spaces are permitted after the backslash. This script produces the following result: Column1 Column2 Column3 Column4 Another example comes from the conversion of a file for troff to an ASCII input format for Ventura Publisher(TM). It converts the following line for troff : .Ah "Major Heading" to a similar line for Ventura: @A HEAD = Major Heading The twist in this problem is that the line needs to be preceded and followed by a blank line. It is an example of writing a multiline replacement string: /^\.Ah/{ s/\.Ah */\ \ @A HEAD = / s/"//g s/$/\ / } The first substitute command replaces - from O'Reilly & Associates' sed & awk , Chapter 5 |
|