Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following command will print out lines in file1.txt with values (anything appearing after <code>=</code>) that do not appear in file2.txt.</p> <pre><code>[me@home]$ awk -F= 'FNR==NR{keys[$0];next};!($2 in keys)' file2.txt file1.txt dbipAddress=192.168.175.130 QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q </code></pre> <p>Breakdown of the command:</p> <pre> awk -F= 'FNR==NR{keys[$0];next};!($2 in keys)' file2.txt file1.txt --- ---------------------- ------------- | | | change the | Target lines in file1.txt where delimiter | the second column (delimited by `=`) do to '=' | not exist in the keys[] array. Store each line in file2.txt as a key in the keys[] array </pre> <p>To do something more elaborate, say if you wish to run the command as a pre-filter to make sure the file is valid before proceeding with your script, you can use:</p> <pre><code>awk -F= 'FNR==NR{K[$0];N++;next};!($2 in K) {print "Line "(NR-N)": "$0; E++};END{exit E}' file2.txt file1.txt ERRS=$? if [ $ERRS -ne 0 ]; then # errors found, do something ... fi </code></pre> <p>That will print out all lines (including line numbers) in file1.txt that do not meet the bill, and returns an exit code that matches the number of non-conforming lines. That way your script can detect the errors easily by checking <code>$?</code> and respond accordingly.</p> <p>Example output:</p> <pre><code>[me@home]$ awk -F= 'FNR==NR{K[$0];N++;next};!($2 in K) {print "Line "(NR-N)": "$0;E++};END{exit E}' file2.txt file1.txt Line 1: dbipAddress=192.168.175.130 Line 5: QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q [me@home]$ echo $? 2 </code></pre>
    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.
    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