title: AWK: redirecting script output from script to another file with dynamic name
body: <p>I know I can redirect awk's print output to another file from within a script, like this:</p>
  
  <pre><code>awk '{print $0 &gt;&gt; "anotherfile" }' 2procfile
  </code></pre>
  
  <p>(I know that's dummy example, but it's just an example...)</p>
  
  <p>But what I need is to redirect output to another file, which has a dynamic name like this</p>
  
  <pre><code>awk -v MYVAR"somedinamicdata" '{print $0 &gt;&gt; "MYWAR-SomeStaticText" }' 2procfile
  </code></pre>
  
  <p>And the outpus should be redirected to <code>somedinamicdata-SomeStaticText</code>.</p>
  
  <p>I know I can do it via:</p>
  
  <pre><code>awk '{print $0  }' 2procfile &gt;&gt; "$MYVAR-somedinamicdata"
  </code></pre>
  
  <p>But the problem is that it's a bigger awk script, and I have to output to several files depending on certain conditions (and this awk script is called from another bash, and it passes some dynamic variable via the -v switch... and son on.</p>
  
  <p>Is it possible anyhow?</p>
  
  <p>Thanks in advance.</p>