Skip to content

Instantly share code, notes, and snippets.

@noahlt
Created October 23, 2011 21:35
Show Gist options
  • Save noahlt/1307915 to your computer and use it in GitHub Desktop.
Save noahlt/1307915 to your computer and use it in GitHub Desktop.
How do I extract a particular column from text (like the output of ps)?

awk has a command for this:

$ awk '{print $2}' <filename>

You can, of course, also pipe in text output from another program:

$ who
noah     console  Oct 21 14:06 
noah     ttys000  Oct 23 13:08 
noah     ttys001  Oct 23 14:00 
noah     ttys004  Oct 22 21:48 
$ who | awk '{print $2}'
console
ttys000
ttys001
ttys004
["awk","column","pipe"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment