Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to operate on part of line only
    primarykey
    data
    text
    <p>How do I make sed operate on specific parts of a line only? And, on the contrary, how do I make sed not work on specific parts of a line?</p> <p>Examples:</p> <pre><code>"A a A a ( A a ) A ( a A ) a" </code></pre> <p>How do I, for instance, replace all the <code>A</code>s with <code>T</code>s <em>only</em> between the <code>(</code> and <code>)</code> to obtain:</p> <pre><code>"A a A a ( T a ) A ( a T ) a" </code></pre> <p>And given next example input:</p> <pre><code>"F f F f ( F f ) F ( f F ) f" </code></pre> <p>How do I, for instance, replace all the <code>F</code>s with <code>X</code>s but <em>not</em> between the <code>(</code> and <code>)</code> to obtain:</p> <blockquote> <p>"X f X f ( F f ) X ( f F ) f"</p> </blockquote> <p>I searched Google but found nothing usable. I guess it's a general question about sed. The problem is reducible to general sed "templates", I hope.</p> <ol> <li>having FROM and TO then operate between them only (on all occurrences on given line)</li> <li>having FROM and TO operate anywhere else than between them...</li> <li>special case when FROM and TO are the same (between " and " or "FOO" and "FOO" etc.) for both 1. and 2.</li> </ol> <p>It should work with any operation, not just substitution, but also with printing etc., like printing everything between strings "FOO" and "BAR" in string.</p> <pre><code>"1 2 3 BAR a b c FOO d e f BAR g a h FOO i j k BAR l m n FOO o p q" </code></pre> <p>The result will be</p> <pre><code>" d e f i j k " </code></pre> <p>So, general examples on how to do it would be highly appreciated. It also seems that this question is quite common, but no good howto is found on the Google yet. I also guess this would be quite challenging to answer. Please, also do no give any hints on how to do it using Perl, AWK or whatever else than sed. This question is really a sed-only question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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