Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>awk</code> can do what you want. For example:</p> <pre><code>$ echo "field1 field2" | awk '{$2 = toupper($2); print;}' field1 FIELD2 </code></pre> <p>Comes pretty close to what you want to do. <code>$2 = toupper($2);</code> changes the second field, while <code>print</code> prints out the whole (modified) line. </p> <p>However, you got a problem in how you define a 'field'. In the example above fields are separated by spaces (you can change the field separator to an arbitrary regexp with like so: <code>-F'&lt;[a-zA-Z]+&gt;'</code> - this would consider as a field separator). But in your example you seem to view <code>&lt;a&gt;</code> as one field and <code>hello world!</code> as another one. Any program could only come to your desired behaviour by wild guessing that way. Why wouldn't <code>world!</code> be considered a third field? So, if you can get input with a clear policy of separating fields, <code>awk</code> is exactly what you want.</p> <p>Check out pages like <a href="http://people.cs.uu.nl/piet/docs/nawk/nawk_92.html" rel="nofollow">http://people.cs.uu.nl/piet/docs/nawk/nawk_92.html</a> (awk string functions) and <a href="http://www.pement.org/awk/awk1line.txt" rel="nofollow">http://www.pement.org/awk/awk1line.txt</a> (awk 1 liners) for more information.</p> <p>BTW, one could also make your specific example above work by looping over all the fields except the first one (NF == Number of Fields): </p> <pre><code>$ echo "&lt;a&gt; hello world! &lt;b&gt; hi everyone! &lt;a&gt; hi" | awk '{for(i=2;i&lt;=NF;++i) { $i=toupper($i); }; print;}' &lt;a&gt; HELLO WORLD! &lt;b&gt; HI EVERYONE! &lt;a&gt; HI </code></pre> <p>Even though you are not interested in the solution to this example. ;-)</p> <p>P.S.: <code>sed</code> should also be able to do the job (http://en.wikipedia.org/wiki/Sed)</p>
    singulars
    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.
    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