💾 Archived View for gem.sdf.org › s.kaplan › cheatsheets › programming-languages › awk.md captured on 2024-03-21 at 15:45:23.
⬅️ Previous capture (2023-09-28)
-=-=-=-=-=-=-
# AWK Cheatsheet ## Overview of unique features - Text processing language - Uses pattern-action paradigm - Built-in variables for manipulating text - Supports regular expressions - Can be used for data extraction and reporting ## Text processing
awk '{print $1}' file.txt
awk '/pattern/ {print}' file.txt
awk '{print toupper($0)}' file.txt
awk '{print length($1)}' file.txt
## Regular expressions
awk '/[0-9]+/ {print}' file.txt
awk '/^start/,/^end/ {print}' file.txt
## Reporting and data extraction
awk -F, '{ sum += $3 } END { print sum }' file.csv
awk '/error/ {print $0}' log.txt
## Resources - [AWK documentation](https://www.gnu.org/software/gawk/manual/gawk.html) - [AWK tutorial](https://www.tutorialspoint.com/awk/index.htm) - [AWK forum](https://stackoverflow.com/questions/tagged/awk) for community support and troubleshooting.