use space as a delimiter with cut command


Question

I want to use space as a delimiter with the cut command.

What syntax can I use for this?

1
288
4/22/2015 1:08:47 PM

Accepted Answer

cut -d ' ' -f 2

Where 2 is the field number of the space-delimited field you want.

325
5/3/2009 11:28:19 AM

Usually if you use space as delimiter, you want to treat multiple spaces as one, because you parse the output of a command aligning some columns with spaces. (and the google search for that lead me here)

In this case a single cut command is not sufficient, and you need to use:

tr -s ' ' | cut -d ' ' -f 2

Or

awk '{print $2}'

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon