You can extract specific columns from text from the command line (Terminal app).
Use awk to extract a column. By default, columns are defined as non-space text separated by one of more whitespace characters (spaces or tabs) but this can be modified.
Here's a simple (pointless) example: echo '111 2 3 4444 5' | awk '{print $2}' This returns "2"
Note 1: The "print" is an awk command which prints a string, then a new line. Note 2: The "$2" means return the second field.
This is useful to return a particular field from another command. Example: ls -al | awk '{print $5}' This displays the size (column 5) of all files in the current directory.
Here's a more complex example which shows the filename and the size, separated with "=": ls -al | awk '{for (i=9; i<=NF; i++) printf $i " "; print "= " $5}' Because the filename can contain spaces we need to show all columns after, and including, column 9.
Note 1: This works because the file name is the last field returned by "ls". Note 2: The variable "NF" is built into awk and stores the number of fields. Note 3: The "printf" awk command displays text without a line break.
You can use a different column separator (instead of the default whitespace) by using the "-F" option.
I usually write a blog post about once a week. The latest post can be viewed here: Peak Fascism: Just so you know: assassinating people who think differently than you is peak fascism! (posted 2025-09-15 at 20:40:57). I do podcasts too!. You can listen to my latest podcast, here: OJB's Podcast 2025-08-07 What is Anything?: Use language in an honest way to communicate instead of obfuscating..