Help with sed Syntax

Grace Quilico quilico at cecom-2.arpa
Tue Nov 25 07:21:16 AEST 1986


Thanks to everyone who responded to my plea for help with the correct
syntax to use for sed in order to interpret carriage-control characters.
Many who responded asked if I was typing the commands directly into the
shell - I was using a file containing the sed commands (e.g., as in
sed -f sed.cmds testfile > sed.out).  Another problem I was having was
that I was not processing the lines beginning with a space in column 1
first - this caused problems (e.g., change the line beginning with a
zero in column 1; now it begins with a space; now process that same line
(incorrectly) as if the space were being used for carriage control).
Anyway!  My shell script looked like this:

cat > sed.cmds <<EOF
s/^1/^L/                   A one in col. 1, used for form feed (Note:
                           use a real <CTRL-L>, not ^L)
/^ /{                      A space in col. 1, used for space (remove it)
	s/ //
	}
/^0/{                      A zero in col. 1, used for double-spacing
	s/0//
	i\\                The following line inserts a newline character

	}
/^-/{                      A dash in column 1, used for triple-spacing
	s/-//
	i\\                The following lines insert 2 newline characters


	}
EOF
sed -f sed.cmds testfile > sed.out
rm -f sed.cmds

Again, thanks to all who responded!

Grace Quilico
Technical Liaison
<quilico at cecom-2.arpa>
AV 995-2275
Comm: (201) 544-2275



More information about the Comp.unix.questions mailing list