Usar AWK para filtrar datos en columnas

    En base a una matriz o entrada de datos, podemos filtrar con awk por columnas.
    Simulamos una tabla con la siguiente información

    1   one       first
    2   two       second
    3   three     third
    4   four      fourth
    5   five      fifth
    6   six       sixth
    7   seven     seventh
    8   eight     eighth
    9   nine      ninth
    10  ten       tenth
    11  eleven    eleventh
    12  twelve    twelfth
    13  thirteen  thirteenth
    14  fourteen  fourteenth
    15  fifteen   fifteenth
    

    Veámos como mostrar los valores 1 y 2 de la columna 1

    root@node01:~# awk '$1 == 1 || $1 == 2' test2.txt 
    1   one       first
    2   two       second
    

    O podemos filtrar por 2 columnas diferentes. En este caso, la columna 1 y 2, deben coincidir:

    root@node01:~# awk '$1 == 1 || $2 == one' test2.txt 
    1   one       first
    

    Leave a Reply

    Your email address will not be published. Required fields are marked *