In the linux shell, the following command will recursively search and replace all instances of 'this' with 'that' (I don't have a Linux shell in front of me, but it should do).
Active3 months ago
What will a similar command on OSX look like?
Powerful Text Search And Replace For Macro![]()
TextWrangler is one of the most user-friendly examples of a text editor, with a price tag to match. Now hosted on the Mac App Store, TextWrangler offers an old-school feel, rock-solid performance, and the option of graduating to a more powerful yet familiar tool (BBEdit, below) if you feel the need. Microsoft Word 2013 has an extensive Find and Replace utility that can help streamline the editing process in your documents. Not only can you find all instances of a word, letter or phrase in a document and replace them, you can find text by its font or style.
46.8k2929 gold badges158158 silver badges223223 bronze badges
Jack
Select Find > Find and Replace in Files or press Ctrl + Shift + F (on Windows), or Cmd + Shift + F (on Mac) to open the Find and Replace dialog box. Note: When Find and Replace in Files is opened for the first time, the Search in Entire Current Local Site is the default option.
Jack
9,6381313 gold badges7979 silver badges148148 bronze badges
Free Search And Replace14 Answers
OS X uses a mix of BSD and GNU tools, so best always check the documentation (although I had it that
less didn't even conform to the OS X manpage):
sed takes the argument after
-i as the extension for backups. Provide an empty string (-i ' Insert text box over picture in word for mac. ) for no backups.
The following should do:
LC_ALL=C find . -type f -name '*.txt' -exec sed -i ' s/this/that/ {} +
The vitaut
-type f is just good practice; sed will complain if you give it a directory or so.-exec is preferred over xargs ; you needn't bother with -print0 or anything.The {} + at the end means that find will append all results as arguments to one instance of the called command, instead of re-running it for each result. (One exception is when the maximal number of command-line arguments allowed by the OS is breached; in that case find will run more than one instance.)
24.1k1515 gold badges9696 silver badges164164 bronze badges
TaylanUBTaylanUB
3,65011 gold badge1212 silver badges1515 bronze badges
For the mac, a more similar approach would be this:
WillWill
1,87011 gold badge1515 silver badges2020 bronze badges
madxmadx
4,35433 gold badges3838 silver badges4848 bronze badges
As an alternative solution, I'm using this one on Mac OSX 10.7.5
Credit goes to: Todd Cesere's answer
Maciej GurbanMaciej Gurban
4,91933 gold badges2424 silver badges4545 bronze badges
eb80eb80
2,81944 gold badges1818 silver badges2828 bronze badges
A version that works on both Linux and Mac OS X (by adding the
-e switch to sed ):
vrocvroc
This is my workable one. on mac OS X 10.10.4
The above ones use find will change the files that do not contain the search text (add a new line at the file end), which is verbose.
NoteCodeNoteCode
If you are using a zsh terminal you're able to use wildcard magic:
sed -i ' 's/search/high-replace/g' *.txt
MentorMentor
Whenever I type this command I always seem to hose it up, or forget a flag. I created a Gist on github based off of TaylanUB's answer that does a global find replace from the current directory. This is Mac OSX specific.
It's nice because now I just pop open a terminal then copy in:
curl -s https://gist.github.com/nateflink/9056302/raw/findreplaceosx.sh | bash -s 'find-a-url.com' 'replace-a-url.com'
You can get some weird byte sequence errors, so here is the full code:
Nate FlinkNate Flink
3,49922 gold badges2525 silver badges1818 bronze badges
https://bitbucket.org/masonicboom/serp is a go utility (i.e. cross-platform), tested on OSX, that does recursive search-and-replace for text in files within a given directory, and confirms each replacement. It's new, so might be buggy.
Usage looks like:
user4425237user4425237
user2725109user2725109
96422 gold badges1717 silver badges3535 bronze badges
I used this format - but..I found I had to run it three or more times to get it to actually change every instance which I found extremely strange. Running it once would change some in each file but not all. Running exactly the same string two-four times would catch all instances.
user1399145user1399145
The command on OSX should be exactly the same as it is Unix under the pretty UI. https://panelrenew898.weebly.com/blog/word-where-to-change-text-direction-word-for-mac.
clopsclops
2,64666 gold badges3232 silver badges4949 bronze badges
Samuel DevlinSamuel Devlin
protected by eyllanescSep 6 '18 at 1:43
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead? Not the answer you're looking for? Browse other questions tagged linuxmacosshell or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |