Re: sed file processing?
Cameron Simpson <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
On 14Feb2014 17:16, Jude DaShiell <[email protected]> wrote: > That's very useful having restrictions on input files being overwritten, > that way we get to see if we like the results before doing anything > permanent. I'm not sure if it was mentioned, but the "-i" flag has two modes. The plain "-i" mentioned lets you overwrite in place. But adding a suffix, eg "-i.bak" or even "-i.bak-`date +%Y%m%d`" takes a backup of the original version as well. On a personal basis I have a script called "bsed": https://bitbucket.org/cameron_simpson/css/src/tip/bin/bsed that does essentially what GNU sed's -i option does (though it rewrites the file instead of making a copy and swapping it in, for reasons I can belabour if anyone really cares), partly to work with non-GNU seds which don't have -i, and partly because it will optionally report a diff and also check the sed output status; a failure such as from a syntacticly invalid sed script won't destroy the input/output file. Cheers, -- Cameron Simpson <[email protected]> Don't have awk? Use this simple sh emulation: #!/bin/sh echo 'Awk bailing out!' >&2 exit 2 - Tom Horsley <[email protected]>