
Con el grep
comando, encontré el texto que necesito de la siguiente manera:
grep 'C02' ~/temp/log.txt
Ahora, dondequiera que encuentre la cadena deseada, me gustaría imprimir la línea que sigue a la cadena encontrada.
Por ejemplo, digamos que el texto deseado es abc
y abc
se encuentra en la línea 12, me gustaría imprimir la línea 13 también.
Respuesta1
Si está utilizando el sistema Linux, puede intentar:
grep -A1 "C02" ~/temp/log.txt
OPTIONS
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing -- between contiguous groups of matches.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing -- between contiguous groups of matches.
-C NUM, --context=NUM
Print NUM lines of output context. Places a line containing -- between contiguous groups of matches.
Puedes usar awk también como:
awk '/C02/{print;getline;print}' ~/temp/log.txt