awk

Linux · Text · available in the simulator

What it does

Processes text by fields and rules.

Syntax

awk [opciones] 'programa' [archivo...]

Options and parameters

  • -F

    Sets the input field separator.

    awk -F: '{print $1}' /etc/passwd
  • -v

    Assigns a variable value before program execution.

    awk -v n=3 '{print $n}' datos.txt
  • -f

    Reads the program source from a file.

  • $1

    References the first field of each record; $0 is the entire record.

    awk '{print $1, $3}' datos.txt
  • NR

    Current record number.

    awk 'NR>1' datos.csv
  • NF

    Number of fields in the current record.

Usage examples

  • awk '{print $1}' archivo
  • awk -F: '{print $1}' /etc/passwd
  • awk -v n=3 '{print $n}' datos.txt
  • awk '{print $1, $3}' datos.txt
  • awk 'NR>1' datos.csv
Practise awk

Related commands