How to pipe output from cat to cut

brenguy asked:

I want to cat /proc/uptime into cut -f1 in a Bash script.

I’ve tried;

cat /proc/uptime | cut -f1
cat /proc/uptime > cut -f1
cut -f1 < cat /proc/uptime

Do I need to use echo or something else to make this happen?

I answered:

The default field delimiter for cut is a tab. Since your file has a space instead, you need to specify the delimiter:

-d ' '

And you really don’t need to use cat or a pipe at all. Just read the file directly.

cut -f 1 -d ' ' /proc/uptime

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.