I want to
cat /proc/uptime into
cut -f1 in a Bash script.
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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
cat /proc/uptime | cut -f1 -d' '
< /proc/uptime cut -f1 -d' '
is correct and more efficient as it reads from
/proc/uptime directly without creating a pipe (not that it matters here much).
It's generally advisable to use the second form on forums, or else you'll get purists coming after you shouting "useless use of cat".
cut -f1 -d' ' < cat /proc/uptime
is wrong. It's the same as
cut -f1 -d' ' /proc/uptime < cat
If you're in bash, you can also use
cut -f1 -d' ' < <(cat /proc/uptime)
This creates an anonymous named pipe for reading and the output of
cat /proc/uptime will be piped into it. But again—useless use of cat.
Other than that,
cut can also take a file argument so all the redirect versions will also work without the
< (it shouldn't matter efficiency-wise):
cut -f1 -d' '/proc/uptime
Or with the <() pipe:
cut -f1 -d' ' <(cat /proc/uptime)