Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I THINK what you're looking for is something like this:</p> <pre><code>awk -F'[,|]' 'NR==FNR{gh[$0];next} {print "set security address-book global", (($2=="group") &amp;&amp; ($3 in gh) ? "address-set" : "address")}' "$group_holder" "your.csv" </code></pre> <p>but it's hard to say without sample "$group_holder" contents and expected output. Hopefully that'll be enough for you to figure out any discrepancies though.</p> <p>Looking at it again, I really don't think you need that "$group_holder" file but you don't tell us where "$temp_file" came from so again - just guessing. If you provide more concrete information in your question we can probably help you more.</p> <p>Based on your updated question, I now think this is what you need:</p> <pre><code>$ awk -F',' '$2=="group" {if (NR==FNR) gh[$1]; else print "set security address-book global address-set", $1, "address" ($3 in gh ? "-set" : ""), $3}' "$temp_file" "$temp_file" set security address-book global address-set group_a address host_a set security address-book global address-set group_a address host_b set security address-book global address-set group_b address-set group_a set security address-book global address-set group_b address host_c </code></pre> <p>and you've GOT to quote your shell variables to avoid word splitting or file name expansion or you're going to get a big surprise some day. Instead of this:</p> <pre><code>time=`date +'%d%m%y_%H%M'` temp_file=temp\_$input_file.txt final=$time\_Parsed_CSV.config </code></pre> <p>Do this:</p> <pre><code>time=$(date +'%d%m%y_%H%M') temp_file="temp_${input_file}.txt" final="${time}_Parsed_CSV.config" </code></pre> <p>Always quote shell variables unless you have a very good, explicit reason not to and understand the consequences fully.</p> <p>Commented version of script per OP request:</p> <pre><code>$ awk -F',' # Use comma as field separator ' $2=="group" { # Only do the following if $2 is "group" if (NR==FNR) # IF this is the first pass of reading the input file THEN gh[$1]; # save the value of the first field as an index in the array "gh" (for "Group Holder") else # ELSE this is the second pass of reading the input file so: print "set security address-book global address-set", $1, "address" ($3 in gh ? "-set" : "") # Ternary operation (google it): # if 3rd field exists as an index of gh then it # was identified as a group during the first pass # of reading the input file so add "-set" to the # already printed "address" so it becomes # "address-set", otherwise leave it as "address". , $3 } # end of if $2 is "group" ' "$temp_file" "$temp_file" # read the input file twice. </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