How to replace "if" to "abc if" in multiple file using shell scripting. But I don't want to change if when it preceded by else?
For example:
if (var3 == 4'h0)
a = bvec[0];
else
if (var3 == 4'h1)
a = bvec[1];
should be converted to
abc if (var3 == 4'h0)
a = bvec[0];
else
if (var3 == 4'h1)
a = bvec[1];
Please note: 1.there are can be indefinite space or a new line between else and if. 2. There are more codes present in the file also 3. I wanted the changes to occur in the same file only. 4. I want to pass a list of filename to the script
I have tried with:
sed -r 's/else[[:blank:]]if/temp1/g;s/if/abc if/g;s/temp1/else if/g' file.v
Here is an example of how to simulate negative variable lookbehind regex in Perl:
Output:
Update:
To use inplace-edit on a list of files:
Then you can just run
p.pl file*.txt
and the backup files will get.bak
suffix.WIth GNU awk for multi-char RS, gensub(), and word boundaries: