Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't use awk and read and write from the same file (is part of your problem).</p> <p>I prefer to rename the file before I rewrite (but you can save to a tmp and then rename too).</p> <pre><code>/bin/mv file file.tmp awk '.... code ...' file.tmp &gt; file </code></pre> <p>If your env file gets bigger, you'll see that is is getting truncated at the buffer size of your OS.</p> <p>Also, don't forget that gawk (the std on most Linux installations) has a built in array ENVIRON. You can create what you want from that</p> <pre><code>awk 'END { for (key in ENVIRON) { print key "=" ENVIRON[key] } }' /dev/null </code></pre> <p>Of course you get everything in your environment, so maybe more than you want. But probably a better place to start with what you are trying to accomplish.</p> <p><strong>Edit</strong> Most specifically</p> <pre><code> awk -F"=" '{ if ($1 in ENVIRON) { printf("%s=%s\n", $1, ENVIRON[$1]) } # else line not printed or add code to meet your situation }' file &gt; file.tmp /bin/mv file.tmp file </code></pre> <p><strong>Edit 2</strong> I think your var=values might need to be <code>export</code> -ed so they are visible to the awk ENVIRON array.</p> <p>AND</p> <pre><code>echo PATH=xxx| awk -F= '{print ENVIRON[$1]}' </code></pre> <p>prints the existing value of PATH.</p> <p>I hope this helps.</p> <p>P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.</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