i'm trying to cut a string into the shell. I'd like to do something like:
cut -d' ' -f1 "hello 12345 xyz"
but the problem is that cut accept a file, so if i pass the string to it, it tries to open the unexistent file called "hello 12345 xyz" and then tries to cut its content
I'd like to resolve this problem with the base programs, so don't tell me to use awk
thanks!
To get cut
to act on a string instead of a file, you have to give it the string via STDIN. The most common way to do so is this:
$ echo 'hello 12345 xyz' | cut -f 1
hello
You can use Here Strings
in BASH
:
cut -d' ' -f1 <<< "hello 12345 xyz"
hello
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