this is my file:
$ cat head_datafile_pipe_deleimiter.csv
"Rec_Open_Date"|"MSISDN"|"IMEI"|"Data_Volume_Bytes"|"Device_Manufacturer"|"Device_Model"|"Product_Description"|"Data_Volume_MB"
"2016-07-17"|"686"|"630"|"618320"|"Apple Inc"|"Apple iPhone S A1530"|"PREPAY PLUS - $0 -"|"0.589676"
"2016-07-17"|"560"|"570"|"42841779"|"Motorola Mobility LLC, a Lenovo Company"|"Moto X 2nd Generation, X112360445"|"$39.95 Plan"|"40.8571"
"2016-07-17"|"811"|"340"|"2465082"|"Samsung Korea"|"Samsung SM-G900I"|"$69.95 Plan"|"2.35089"
"2016-07-17"|"785"|"610"|"41498628"|"Apple Inc"|"Apple iPhone 6S Plus A1687"|"$29.95 Carryover Plan 1GB"|"39.5762"
"2016-07-17"|"908"|"310"|"6497563"|"Samsung Korea"|"Samsung GT-I9195"|"PREPAY PLUS - $0 -"|"6.19656"
"2016-07-17"|"919"|"610"|"0"|"Samsung Korea"|"Samsung SM-G925I"|"$19 CO COMBO - NOT RECURRENT"|"0"
"2016-07-17"|"356"|"290"|"33189681"|"Apple Inc"|"Apple iPhone 6S A1688"|"$39.95 Plan"|"31.6521"
"2016-07-17"|"009"|"160"|"30340"|"Samsung Korea"|"Samsung SM-J500Y"|"PREPAY PLUS - $1 - #33"|"0.0289345"
"2016-07-17"|"574"|"400"|"549067"|"HUAWEI Technologies Co Ltd"|"HUAWEI Y6"|"PREPAY PLUS - $0 -"|"0.523631"
and here I am close to what I want but i cannot get it to iterate through the differnet elements in the array. if($7==dq"PREPAY PLUS - $0 -"dq) print $7. It is basically a for loop that iterates trhough the elements in the array, and there for filters out the value I want before moving onto the next element in the array and repeating. But I can only get it to work if I hard code the value, I want it to iterate through the array u_vals
$ for i in "${u_vals[@]}"; do awk -F'|' -v var="${u_vals[*]}" -v j=i -v dq='"' 'NR==1{print $7} NR>1{split(var,list,"|"); if($7==dq"PREPAY PLUS - $0 -"dq) print $7 }' head_datafile_pipe_deleimiter.csv; done
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
these are all the uniq value in column 7
$ printf "%s\n" "${u_vals[@]}"
"$19 CO COMBO - NOT RECURRENT"
"$29.95 Carryover Plan 1GB"
"$39.95 Plan"
"$69.95 Plan"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $1 - #33"
How do I make this part
dq"PREPAY PLUS - $0 -"dq
of this
if($7==dq"PREPAY PLUS - $0 -"dq) print $7
iterate through the elements of the array?
EDIT1
this is what I was looking for:
awk -F"|" ...
$ for i in "${u_vals[@]}"; do awk -F"|" -v j="$i" 'NR==1{print $7}NR>1 {if($7==j) print $7 }' head_datafile_pipe_deleimiter.csv ; done
"Product_Description"
"$19 CO COMBO - NOT RECURRENT"
"Product_Description"
"$29.95 Carryover Plan 1GB"
"Product_Description"
"$39.95 Plan"
"$39.95 Plan"
"Product_Description"
"$69.95 Plan"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $1 - #33"
awk -v FS="|" ....
$ for i in "${u_vals[@]}"; do awk -v FS="|" -v j="$i" 'NR==1{print $7}NR>1 {if($7==j) print $7 }' head_datafile_pipe_deleimiter.csv ; done
"Product_Description"
"$19 CO COMBO - NOT RECURRENT"
"Product_Description"
"$29.95 Carryover Plan 1GB"
"Product_Description"
"$39.95 Plan"
"$39.95 Plan"
"Product_Description"
"$69.95 Plan"
"Product_Description"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"PREPAY PLUS - $0 -"
"Product_Description"
"PREPAY PLUS - $1 - #33"
u_vals?u_vals?