Change multiple files

I’m surprised nobody has mentioned the -exec argument to find, which is intended for this type of use-case, although it will start a process for each matching file name: find . -type f -name ‘xa*’ -exec sed -i ‘s/asd/dsg/g’ {} \; Alternatively, one could use xargs, which will invoke fewer processes: find . -type f … Read more

Remove multi-line comments

Here’s one way using GNU sed. Run like sed -rf script.sed file.txt Contents of script.sed: :a s%(.*)/\*.*\*/%\1% ta /\/\*/ !b N ba Alternatively, here’s the one liner: sed -r ‘:a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba’ file.txt

How to escape single quote in sed?

Quote sed codes with double quotes: $ sed “s/ones/one’s/”<<<“ones thing” one’s thing I don’t like escaping codes with hundreds of backslashes – hurts my eyes. Usually I do in this way: $ sed ‘s/ones/one\x27s/'<<<“ones thing” one’s thing