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