Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>sed -r $'s/(\$LD = )(\'.*\')(.*)/\\1_(\\2)\\3/' filename </code></pre> <p>Example:</p> <pre><code>$ echo "\$LD = 'Some String';" | sed -r $'s/(\$LD = )(\'.*\')(.*)/\\1_(\\2)\\3/' $LD = _('Some String'); </code></pre> <p><strong>Edit:</strong></p> <p>This will look for and change both variables, the <code>-i</code> will make the change in-place:</p> <pre><code>sed -i -r $'s/(\$(LD|Another) = )(\'.*\')(.*)/\\1_(\\3)\\4/' </code></pre> <p>You can list more variable names separated by pipe characters.</p> <p>Your <code>grep</code> command needs single quotes instead of backticks and a <code>-E</code> to use extended regexes. It also needs a filespec glob. The regex as you have basically says "Does this file have any variable definitions?" It says to look for any variable that:</p> <ul> <li>starts at the beginning of the line with no whitespace before it</li> <li>has zero or more array subscripts consisting of zero or more digits (which would include a null subscript, thus an array append)</li> <li>ignore any associative array assignments (<code>$array["key"]=value</code>)</li> <li>the line must end in a semicolon</li> <li>I'm not sure what the <code>?</code> is intended to do</li> </ul> <p>This fails if the variable assignment:</p> <ul> <li>occurs after some whitespace</li> <li>uses an alpha key or a variable as a key</li> <li>occurs on a line with other statements</li> <li>has any trailing whitespace</li> <li>possibly others</li> </ul> <p>You might need to make your regex more robust or simpler or just assume that any PHP file will have a variable assignment and let <code>sed</code> look for and change just the variables of interest.</p> <p>In order for your <code>grep</code> to have files to process, you need to specify which files to look at:</p> <pre><code>grep -E -i -R 'your regex' * | sed ... </code></pre> <p>Or, if you let <code>sed</code> do it:</p> <pre><code>find . -name "*.php" | sed ... </code></pre> <p>Also, a tool called <a href="http://betterthangrep.com/" rel="nofollow noreferrer"><code>ack</code> is better than <code>grep</code></a> for finding stuff in code files.</p> <p>In any case, especially if you use the in-place option, <em>I strongly recommend test runs (and backups).</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload