34.3 Testing and Using a sed Script: checksed, runsedAll but the simplest sed scripts are often invoked from a "shell wrapper," a shell script ( 44.1 ) that invokes sed and also contains the editing commands that sed executes. A shell wrapper is an easy way to turn what could be a complex command line into a single-word command. The fact that sed is being used might be transparent to users of the command. Two shell scripts that you should immediately arm yourself with are described here. Both use a shell for loop ( 44.16 ) to apply the same edits to any number of files. But the first just shows the changes, so you can make sure that your edits were made correctly. The second writes the edits back into the original file, making them permanent. 34.3.1 checksed
For example:
$ If you find that your script did not produce the results you expected, perfect the editing script and run checksed again. 34.3.2 runsed
runsed only modifies a file if your sedscr made edits. So, the file's timestamp ( 16.5 ) won't change if the file's contents weren't changed. Like checksed , runsed expects to find a sed script named sedscr in the directory where you want to make the edits. (Article 4.3 describes a way to keep many sed scripts.) Supply the name or names of the files to edit on the command line. Shell metacharacters ( 15.2 ) can be used to specify a set of files:
$ runsed does not protect you from imperfect editing scripts. You should use checksed first to verify your changes before actually making them permanent with runsed . (You could also modify runsed to keep backup copies of the original versions.) - , , |
|