# Awk

## Definicion

En términos generales el comando awk permite procesar y modificar el texto según nuestras necesidades.

Los usos básicos que podemos dar al comando Awk son los siguientes:

1. Buscar palabras y patrones de palabras y reemplazarlos por otras palabras y/o patrones.
2. Hacer operaciones matemáticas.
3. Procesar texto y mostrar las líneas y columnas que cumplen con determinadas condiciones.

***

## Uso

* Ejemplo basico tomar primer *Columna* del output.

```bash
ps | awk '{print $1}'
```

* Ejemplo tomar *ultima* Columna del output

```bash
ps | awk '{print $NF}'
```

* Delimitar por otro *Caracter*

```bash
ps | awk -F ":" '{print $2 "\t" $3 "\n" $4}' 
```

* *Condiciones* en awk: Puedes usar condiciones en `awk` para filtrar líneas específicas. Por ejemplo, para imprimir solo las líneas donde la segunda columna es *mayor* que 10:

```bash
ps | awk '$2 > 10 {print $1}'
```

* **Expresiones regulares**: Puedes utilizar expresiones regulares para buscar y manipular texto. Por ejemplo, para encontrar líneas que contengan la palabra "kernel":

```bash
ps | awk '/kernel/ {print $1}'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tluisillo-o.gitbook.io/blog/linux-utilities/awk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
