Forum Moderators: travelin cat
One command I've seen is..
awk Find and Replace text within file(s)
but that just gives out
[Jesse-Smiths-Computer: Future content] strago% awk
Usage: awk [-f programfile ¦ 'program'] [-Ffieldsep] [-v var=value] [files]
To see their capabilities you'll have to access the man pages for these utilities: 'man awk' and 'man sed'.
Another utility that might come in handy is xargs.
Also, you'll have to actually write a shell script. Depending on you shell (either tcsh or bash) you'll want to read 'man tcsh' or 'man bash'. For examples of what's possible see [webmasterworld.com...] . Also, in order for your script to do what you describe it'll have to be a recursive script - and they can be *very* dangerous to play with if you aren't careful.
On the other hand, if you have the means to invest in BBEdit, doing what you've described is very easy in BBEdit. As I can see from your question that you've got no experience at all using the Terminal (otherwise you would have known to use 'man awk' to get the needed info) I'll recommend investing in BBEdit. The time you'll save is more than worth the investment. Learning to use Terminal and the cli is no simple process - it's nerdy as hell and has a *very* steep learning curve.
Learning to use Terminal and the cli is no simple process - it's nerdy as hell and has a *very* steep learning curve.
OK, I'll concede on nerdy, but the learning curve isn't that steep. Use the terminal a little every day and in 6 months the Linux folks may start coming to you for advice.
But I digress. Yes, BBEdit's Find and Replace will work fine for this simple replace, as will a lot of other Web development apps, such as Dreamweaver.
If you want to dip your toe into the more powerful search and replace functions of Unix, just check the "Use GREP" box in BBEdit and start reading up on Regular Expressions.
Will BBEdit's Find and Replace do mass search and replaces from hundreds of files at once? The current program I got was made for OS9, TexFinder, so when you try to do a lot of files at once, like just a few hundred, it get's slow, since it uses Classic. One of these days I'll try to figure out that terminal stuff.
Will BBEdit's Find and Replace do mass search and replaces from hundreds of files at once?
Yes, it should crank through that pretty quickly, assuming the files aren't huge. But you'll probably want to uncheck "Confirm Saves" and "Show Results" once you're sure it's working.
The only time I've ever notice BBEdit really slowing down is when it needs to open up really big files, and your Mac doesn't have the RAM to cope.
One of these days I'll try to figure out that terminal stuff.
If you really want to boss around your text files, learn a little Perl. (It's already installed on your Mac.
Is there any way to do the search and replace with out all the changed files being opened?
Yes. Just created 2000 files (with a quick and easy shell script) and did the replace on them in a few seconds. No files opened. I'm using BBEdit 8 but I don't recall this feature changing recently.
I think you just have to fiddle with the settings in the "Find & Replace All Matches" -- check "Save to Disk" and nothing else.
perl -pi.old -e 's/\.html/.shtml/g' *.html
The ".old" tells perl to back-up the files first with the extension ".old" appended. eg. index.html will be backed up to index.html.old while the new index.html is modified. Leave out the ".old" if you want to live on the edge.
The "s/regexp/replacement/g" is a substitution:
s = substitute;
g = globally;
regexp = pattern to match
replacement = replacement text
*.html is the list of files to apply the substitution on (* is a wild-card in this case)
Warning! you are guaranteed to type the command wrong at least once with the result that the contents of all your files will be deleted (I must have done this a half-dozen times ;))