[SOLVED] Simple bash string manipulation - well it should be
by GPGAgent from LinuxQuestions.org on (#5AAAC)
I have a file name, abcdefgh.mp4 and I want to just get the last four characters of the name "efgh" (okay - I know files in linux don't have extensions like in Windoze it's alll just part of the name)
I can do it with an intermediate variable, but I want one neat bit of bash:Code:$ echo $ff ${ff%.*}
5f391985dc5a423cb7d31.mp4 5f391985dc5a423cb7d31So far so good and I could do this:Code:$ X=${ff%.*}
$ echo ${X: -4}
7d31Or this, but it presumes the filenames are always the same length:Code:~$ ff=5f391985dc5a423cb7d31.mp4
~$ echo ${ff:17:4}
7d31But I would like a one liner please


I can do it with an intermediate variable, but I want one neat bit of bash:Code:$ echo $ff ${ff%.*}
5f391985dc5a423cb7d31.mp4 5f391985dc5a423cb7d31So far so good and I could do this:Code:$ X=${ff%.*}
$ echo ${X: -4}
7d31Or this, but it presumes the filenames are always the same length:Code:~$ ff=5f391985dc5a423cb7d31.mp4
~$ echo ${ff:17:4}
7d31But I would like a one liner please