Frage

I want to run a sed command : sed command to replace if( with if (

My command looks like this:

sed 's/if(/if ( /g' file1.c >file1.c

where file1.c contains the string that needs to be replaced.

Problem is file contents gets cleared and no changes are reflected.

War es hilfreich?

Lösung

You can try two different approaches.

If you want to update existing file:

sed -i 's/if(/if ( /g' file1.c  

If you want to store the modified file in another file:

sed 's/if(/if ( /g' file1.c > file2.c  

Andere Tipps

Use this:

sed -re 's/if(/if ( /g' 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top