Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut command not working on linux [closed]

I am trying this:

echo "This is test" | cut -f 1

and it is not cutting anything, I get this:

This is test

like image 642
user2024264 Avatar asked Oct 15 '25 18:10

user2024264


1 Answers

By default, cut doesn't split on space, only on tab. If you tell it to split on space, then it won't split on tab. Also, consecutive spaces or tabs will add empty fields to the set.

If you want to split on "any amount of any kind of whitespace", you're better off with awk:

echo "This is a test" | awk '{print $1}'

Also, you can replace echo...| with <<< in bash:

awk '{print $1}' <<<"This is a test"
like image 100
Mark Reed Avatar answered Oct 18 '25 12:10

Mark Reed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!