I have an awk script that receives some parameters and filters data from given csv file according to those parameters.
there are 2 outputs:
- First, it writes a .csv file with all the records that match parameters.
- Then, it prints only the field $2 which refers to name of records. But it should be a random subset of 20 records.
So far, I have done this:
I call the script this way: ./Script.awk ARG1=20 ARG2="AAA" ARG3=1900 data.csv
#! /usr/bin/awk -f
# Define FS
BEGIN {FS=OFS = ","}
$4 > ARG1 && $8 == ARG2 && $20 > ARG3 { print > "filtered_data.csv" ; print $2 }
So, it creates correctly the filtered data file and print $2, but there are many records, therefore I would like to print only a random subset. So, any idea how can it be done?
Thanks!!
ARGV[1]
, using all upper case letters which could clash with builtins, and completely missing the point of variable names - they should identify what the value they hold means, not what position it occurs in or anything else.