There are three types of line range specifications:
Ahello jimappends hello jim to all lines in the file. The <text> can be maximally 80 characters.
/blah/Ineedle noddle nooinserts needle noddle noo at the start of all lines that contain blah. The <text> can be maximally 80 characters.
1,1/OThe TitleInserts a new line before the first line in the file, containing the text The Title. The <text> can be maximally 80 characters. The new line is not put through the editing process.
3,6/ddeletes lines 3 to 6 inclusive.
/filename/s/.pas/.c/replaces the first occurrence of .pas with .c, in all lines containing filename. The <old text> and <new text> can be maximally 80 characters.
Read in and store the edit commands from the file Read a line from standard input While not at EOF of standard input For each edit command do If the line is in the range specified then Do the edit Output the edited line (unless it has been deleted) Read a line from standard input
/Never done/I--------------------------------------- 1,3/IPrepended to 1,2 and 3 : 1,1/OThis must appear as the first line A : Appended to all /line for substitution/s/This is one/This has been substituted on a/ 9,10/d /deleted/IThis should not appear /Never done/I---------------------------------------and the standard input is:
L1 To have text prepended L2 To have text prepended L3 To have text prepended L4 Unmodified except appended text L5 Unmodified except appended text L6 Unmodified except appended text L7 This is one line for substitution L8 This is one line for substitution L9 This is to be deleted L10 This is to be deleted L11 The last line of the filethen the standard output is:
This must appear as the first line Prepended to 1,2 and 3 :L1 To have text prepended : Appended to all Prepended to 1,2 and 3 :L2 To have text prepended : Appended to all Prepended to 1,2 and 3 :L3 To have text prepended : Appended to all L4 Unmodified except appended text : Appended to all L5 Unmodified except appended text : Appended to all L6 Unmodified except appended text : Appended to all L7 This has been substituted on a line for substitution : Appended to all L8 This has been substituted on a line for substitution : Appended to all L11 The last line of the file : Appended to all
Input | Command file | Expected output |