Forrest logo
back to context overview

awk

List of commands for awk:

  • awk:ai:193be replace column with awk
    $ awk -F',' '{ $2 = "replacement_text" } 1' file.csv
    try on your machine
    explain this command
  • awk:ai:5e4c8 awk
    $ awk
    try on your machine
    explain this command
  • awk:ai:9a3ab Edit a file in place with awk by replacing 'pattern' with 'replacement'
    $ awk -i inplace '/pattern/{replacement}' file
    try on your machine
    explain this command
  • awk:ai:a3ddf format output file with awk
    $ awk -F "\t" 'BEGIN{print "{\"cli command\":\"${command}\", \"description\":\"${description}\"},"} {print "{\"cli command\":\""$1"\", \"description\":\""$2"\"},"}' input_file | awk 'NR>1{print p} {p=$0} END{printf "%s\n]", p}'
    try on your machine
    explain this command
  • awk:ai:a64a1 Delete a single line from a given file with awk
    $ awk '!/pattern/' filename > newfile
    try on your machine
    explain this command
  • awk:ai:d3723 cut lines with awk
    $ awk 'BEGIN{ FS = "|" } { print $1 }' ${filename}
    try on your machine
    explain this command
  • awk:ai:f75b1 How to edit a file with awk
    $ awk 'pattern { action }' filename
    try on your machine
    explain this command
  • awk:tldr:16f09 awk: Print different values based on conditions.
    $ awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' ${filename}
    try on your machine
    explain this command
  • awk:tldr:39f5d awk: Print the fifth column (a.k.a. field) in a space-separated file.
    $ awk '{print $5}' ${filename}
    try on your machine
    explain this command
  • awk:tldr:56083 awk: Sum the values in the first column of a file and print the total.
    $ awk '{s+=$1} END {print s}' ${filename}
    try on your machine
    explain this command
  • awk:tldr:5662d awk: Print the last column of each line in a file, using a comma (instead of space) as a field separator.
    $ awk -F ',' '{print $NF}' ${filename}
    try on your machine
    explain this command
  • awk:tldr:88dc4 awk: Print all the lines which the 10th column value is between a min and a max.
    $ awk '($10 >= min_value && $10 <= max_value)'
    try on your machine
    explain this command
  • awk:tldr:89541 awk: Print every third line starting from the first line.
    $ awk 'NR%3==1' ${filename}
    try on your machine
    explain this command
  • awk:tldr:aea97 awk: Print all lines where the 10th column value equals the specified value.
    $ awk '($10 == value)'
    try on your machine
    explain this command
  • awk:tldr:e6726 awk: Print the second column of the lines containing "foo" in a space-separated file.
    $ awk '/${foo}/ {print $2}' ${filename}
    try on your machine
    explain this command
back to context overview