Bueno, claramente, mawk no tiene una función strftime.
no tengo mawk aquí, así que no probado:
awk -f script -v the_year=$(date "+%Y") inputFile
y script
ha (la combinación de las dos expresiones regulares:
$2 ~ /^[HB].*n$/ { print the_year }
Si el año debería ser entre $ 0 de alguna manera, entonces debería ser capaz de analizarlo fuera de la cadena. Danos más detalles sobre tu entrada.
EDIT
the input is made of several rows that look like this: "12768 Ashwari F 20 11 1985". Basically I have to filter all those with a name that begins with B or H and ends with n. In addition I have to calculate the age of each filtered student and find out the average age of the entire group.
awk -v this_year=$(date +%Y) -v today=$(date +%Y%m%d) '
$2 ~ /^[BH].*n$/ {
age = this_year - $6
if (today < $6 $5 $4) { age-- } # I assume those fields are the birthday
total_age += age
count ++
print $2 " is " age " years old"
}
END {
print "average age = " total_age/count
}
' inputFile
Hola Glenn, la entrada está hecha de varias filas que se ven así: "12768 Ashwari F 20 11 1985". Básicamente tengo que filtrar todos aquellos con un nombre que comienza con 'B' o' H' y termina con 'n'. Además, debo calcular la edad de cada alumno filtrado y conocer la edad promedio de todo el grupo. Saludos, Ariel. –
Esta es una buena idea y funciona en algunos casos. Pero a veces es necesario que repita la llamada de marca de tiempo, por ejemplo, para los mensajes de registro, y en este caso no ayuda. – erikbwork