Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your shell appears to have limited you. I suspect that your guess is correct, and this isn't an awk problem, it's the scripting language from which you're calling awk.</p> <p>You can pre-load awk with variables loaded from a file. Check this out:</p> <pre><code>$ printf 'foo=2\nbar=3\nbaz=4\n' &gt; vars $ printf 'snarf\nblarg\nbaz\nsnurry\n' &gt; text $ awk 'NR==FNR{split($0,a,"=");vars[a[1]]=a[2];next} $1 in vars {print vars[$1]}' vars text 4 $ </code></pre> <p><strong>How does this work?</strong></p> <p>The first two printf lines give us our raw data. Run them without the redirect (or cat the resultant files) if they're not completely clear to you.</p> <p>The awk script has two main sections. Awk scripts consist of repetitions of <code>condition { commands }</code>. In this case, we've got two of these sets.</p> <p>The first set has a condition of <strong><code>NR==FNR</code></strong>. This evaluates as "true" if the current record number that awk is processing (NR) is the same as the current record number in the current file. Obviously, this only works for the FIRST file, because as of the first line in the second file, NR is 1 plus the line count of the first file.</p> <p>Within this section, we <code>split()</code> the line according to its equals sign, and put the data into an array called <code>vars</code>.</p> <p>The second set has a condition of <strong><code>$1 in vars</code></strong>, which evaluates to true if the first word of the current line exists as a subscript of the <code>vars</code> array. I include this only as an example of what you can do with vars, since I don't know what you're trying to achieve with these variables.</p> <p>Does this address your problem? If not, we'll need to see some of your code to get an idea of how to fix it.</p> <hr> <p><strong>UPDATE</strong> per suggestion in comments, here's proof that it works for large variables:</p> <p>First, we prepare our input data:</p> <pre><code>$ dd if=/dev/random of=out.rand count=128k bs=1k 131072+0 records in 131072+0 records out 134217728 bytes transferred in 3.265765 secs (41098404 bytes/sec) $ b64encode -o out.b64 out.rand out.rand $ ls -lh out.b64 -rw-r--r-- 1 ghoti wheel 172M Jul 17 01:08 out.b64 $ awk 'BEGIN{printf("foo=")} NR&gt;1{printf("%s",$0)} END{print ""}' out.b64 &gt; vars $ ls -lh vars -rw-r--r-- 1 ghoti wheel 170M Jul 17 01:10 vars $ wc -l vars 1 vars $ cut -c1-30 vars foo=orq0UgQJyUAcwJV0SenJrSHu3j </code></pre> <p>Okay, we've got a ~170MB variable on a single line. Let's suck it into awk.</p> <pre><code>$ awk 'NR==FNR{split($0,a,"=");vars[a[1]]=a[2];next} END{print length(vars["foo"]);print "foo=" substr(vars["foo"],0,26);}' out.var bar 178956971 foo=orq0UgQJyUAcwJV0SenJrSHu3j </code></pre> <p>We can see the size of the variable, and the first 26 characters match what we saw from shell. Yup, it works.</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. 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.
    3. 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