Scenario
I am trying to use cut command to get the 4th field from a file that has the redirected output of a df command. But it's only cutting and returning the 1st field for some reason.
df -kh -B 1g /ws/abc-Location03 > file1.txt
cut -d" " -f4 file1.txt
Output of my df command
Filesystem 1G-blocks Used Available Use% Mounted on
abc5-xyz04c:/root_vdm_6/t2local24/abc-Location03
500 408 93 82% /ws/abc-Location03
Output of my cut command
abc5-xyz04c:/root_vdm_6/t2local24/abc-Location03
Basically, it's cutting just the 1st field and returning it, instead of the 4th field. I 'd like to know what it is I'm doing wrong.
Because you're delimiting on whitespace and not repeated whitespace, your columns are messed up. Try this:
df -kh -B 1g | tr -s ' ' | cut -d ' ' -f 4
The tr turns all repeated spaces into single spaces, so you can cut them as you please.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With