
Tengo este código.Me gustaría agregar un parámetro(nombre de un aeropuerto)a dicho código. Entonces, dado el nombre de un aeropuerto, obtendría el mismo resultado pero solo para ese parámetro dado.
Código:
Obtenga el porcentaje de vuelos retrasados, el número total de vuelos retrasados y el número total de vuelos, en cada día de la semana.
BEGIN { FS = OFS = "," }
FNR > 1 {
total[$2]++; if ($6) delay[$2]++ }
END {
print "\"weekday\"", "\"percentage_delayed\"", "\"delayed\"", "\"total_flights\""
for (day in total) { print day, delay[day] / total[day] * 100, delay[day], total[day]}
}
Aporte:
Las columnas 3 y 4 son los nombres de los aeropuertos.
"DAY_OF_MONTH","DAY_OF_WEEK","ORIGIN","DEST","DEP_TIME","DEP_DEL15","CANCELLED","DIVERTED","DISTANCE"
1,Tuesday,ORD,GRB,1003,0.00,0.00,0.00,322.248
1,Tuesday,TUL,ORD,1027,0.00,0.00,0.00,1083.42
1,Tuesday,EWR,TYS,1848,0.00,0.00,0.00,1168.61
Producción:
"weekday", "percentage_delayed", "delayed", "total_flights"
Tuesday,10.7912,446,4133
Moday,10.2564,336,3276
Friday,26.6401,735,2759
¿Cómo puedo agregar un parámetro al código, de modo que solo muestre el resultado de ese parámetro determinado?
Gracias
Respuesta1
$ awk -v origin='ORD' -v dest='GRB' '
BEGIN { FS=OFS= "," }
FNR > 1 && $3==origin && $4==dest { total[$2]++; if ($6) delay[$2]++ }
END {
print "weekday", "percentage_delayed", "delayed", "total_flights"
for (day in total)
print day, delay[day] / total[day] * 100, delay[day]+0, total[day]
}' infile
En lo anterior -v origin='ORD'
se -v dest='GRB'
definen como parámetros del script awk, cámbielos según sus necesidades.