


One symbol in the script messed up all my txt files, and I didn’t back up!!! There was simply no way back. ~/Desktop/ exampleScript Again, make sure to backup everything before executing the script!!! Simply type the script in Terminal including all path, e.g. Part 4 (Almost there!): Execute the script You could also give them 7 if you want (chmod 777 curlscript), etc. You want yourself to be able to write to the file and execute it (7) and you want everyone else to be able to read it or execute it but not write it (5). The 755 is made up of three digits, that represent the permissions for you, others in your “user group” and all others. This command changes the file’s permission, so it is executable. Make sure the script is executable, type in Terminal: c hmod 755 ~/Desktop/ exampleScript Save all commands in the above format in a plain text file. If you want to be able to replace the same strings again, please read on!!! Part 3: Create a executable script file Now you can already replace multiple strings in multiple txt files. The standard syntax in Terminal, end every command with a “ ” If you need to repetitively find & replace same strings in multiple text files, then please read on. So, if you just need to replace one string in batch, simply launch Terminal and type this line. g: make the substitution globally.that is don’t stop after first replacement.-i.bak: change the input file ( filename) in place and create the file filename.bak as backup.-p: assume ‘ while () ‘ loop around program and print each processed line too.The command is: perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g ' PATH/ *.txtĮxample: Replace ‘ Lucy‘ with ‘ 露西‘ in all txt files in a dropbox folder called ‘ txtFiles‘: perl -pi -w -e 's/ Lucy/ 露西/g ' ~/Dropbox/txtFiles/ *.txt Make sure you backup all the files before run the script!!!! Part 1: Single line to execute “Find & Replace”Įxtract from: How to Quickly Find and Replace Text Across Multiple Files with One Command There might be limitations in encodings, but I didn’t do any experiment on that.Perhaps there is a parameter to tweak that, but I didn’t manage to find it. Case sensitive (For me it is a disadvantage, but it doesn’t have to be bad.Some symbols can mess up the whole file.Can be quite slow when there are hundreds of txt files.In Mac OS system, repetitively replace same strings in a large number of plain text files.

This is a step-by-step instruction for people who are totally oblivious to the wonderland of programming and coding, people like me 🙂 Suitable scenario:
