script help

Roland Smith rsmith at xs4all.nl
Mon Feb 14 22:54:09 UTC 2011


On Mon, Feb 14, 2011 at 04:34:37PM -0600, Jack L. Stone wrote:
> # find all of the same filenames (copyright.htm) and then replace the year
> 2010 with 2011 in each file. Once I have a working script, I should be able
> to add it as a cron job to run on the first day of each new year.

The following command should do the trick, I think.

find / -type f -name copyright.htm -exec sed -i .bak -e 's/Copyright © 20../Copyright © 2011/g' {} \;

Basically the find(1) command locates the files you want to change, and than
for every file it calls sed(1) with the -i flag to do the in-place
editing. The originals are saved as copyright.htm.bak. If all goes well, you
can delete those.

Depending on the contents of the files, you might want to just replace 2010 by
2011, or use a little more context as I did in the example, to make sure only
the right numbers are replaced.

Roland
-- 
R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20110214/8d2af63f/attachment.pgp


More information about the freebsd-questions mailing list