There is a sample of using the cut
command to extract parts of a string starting from the left. An example is given below.
$ echo "abc-def-ghi-jkl" | cut -d- -f-2
abc-def
How can the same code be adapted to extracting from the right side? I thought of reversing the words and applying the same method, but it was too complicated.
you could use rev
echo "abc-def-ghi-jkl" | rev | cut -d- -f-2 | rev
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