sed -f scriptfile file
All the editing commands that we want executed are placed in a file.
We follow a convention of creating temporary script files named
sedscr.
$ cat sedscr
s/ MA/, Massachusetts/
s/ PA/, Pennsylvania/
s/ CA/, California/
s/ VA/, Virginia/
s/ OK/, Oklahoma/
The following command reads all of the substitution commands in
sedscr and applies them to each line in the input
file list:
$ sed -f sedscr list
John Daggett, 341 King Road, Plymouth, Massachusetts
Alice Ford, 22 East Broadway, Richmond, Virginia
Orville Thomas, 11345 Oak Bridge Road, Tulsa, Oklahoma
Terry Kalkas, 402 Lans Road, Beaver Falls, Pennsylvania
Eric Adams, 20 Post Road, Sudbury, Massachusetts
Hubert Sims, 328A Brook Road, Roanoke, Virginia
Amy Wilde, 334 Bayshore Pkwy, Mountain View, California
Sal Carpenter, 73 6th Street, Boston, Massachusetts
Once again, the result is ephemeral, displayed on the screen. No
change is made to the input file.
If a sed script can be used again, you should rename the script and
save it. Scripts of proven value can be maintained in a personal or
system-wide library.