Search code examples
regexperlack

Excluding lines that contain a pattern before replacing in Perl


I have the following code to replace version string from a set of files

ack --ignore-file=is:HISTORY.md -l --print0 '1\.1\.1' | xargs -0 perl -pi -e 's/1\.1\.1/1\.1\.2/g' 

Now, I realized there are some lines in the doxygen comment that also have the version string like this.

/**
 * Generate Tag id from Tag name
 *
 * @since 1.1.1
 * @static
 * @access public
 *
 */

How can I modify the above snippet so that lines that contain @since will be excluded?


Solution

  • To exclude lines with @since you could try this instead of your current perl replace code:

    !/\@since/ && s/1\.1\.1/1.1.2/g
    

    or even

    /\@since/ || s/1\.1\.1/1.1.2/g