← Blog

Awk - Procesamiento de Texto

Apuntes y comandos de Awk - Procesamiento de Texto para Linux.

# awk, breaks each input line into separate fields
# default delim is space

echo first second third | awk '{print $2}'
# second
# space-separated words, awk prints 2nd word

awk -F ',' '{print $1}' sample.txt
# -F for delimiter
# prints first field from comma separated values in each line

awk -F ',' '{print $1}' sample.txt | awk '{print $2 "," $1}'
# print first field from comma separated values, then reorder as last name, first name

awk -F ',' '/Dakota/ {print NR,$1}' sample.txt
# print first field with comma delim
# only from lines which have 'Dakota'
# NR prints record number or row number