Skip to content
Advertisement

linux replace string in files recursively

I have a folder which is full of *.java files. it has the following method in it:

JavaScript

i wanted to change this as following:

JavaScript

I have searched in the forum and found some solutions, replce string is what i wanted so tried the following:

JavaScript

But it throwing me the following error:

JavaScript

I guess the old_string and new_string formates are the problem here. how can I fix it, or do it in a more efficient and meaningful way.

Advertisement

Answer

If GNU sed is available, how about:

JavaScript

The -z option to sed assigns the line delimiter to NUL character which enables to slurp whole lines separated by newline characters.

If you want to perform the same substitution on the *.java files recursively, please try:

JavaScript

As the -i option forces to overwrite the original files, make sure to backup the files (or put the backup suffix to the -i option) before the test.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement