I've searched a great deal and have seen many ways to modify other
parts of the filename but not retain everything before a specific
character (_) and the extension.
Este sed
parece fazer o truque:
sed -E 's/(.*)_[0-9].* by .*(\.wav)//'
echo "/home/user/recordings/TEST/december/157A757989F047C3AC2EC3499B4D04A5_7075276189 by [email protected] @ 8_44_52 AM.wav" | sed -E 's/(.*)_[0-9].* by .*(\.wav)//'
/home/user/recordings/TEST/december/157A757989F047C3AC2EC3499B4D04A5.wav
Testando na sua outra string de exemplo:
echo "/home/user/recordings/test/october/28D1E1840DE24D9DB4CF6D1A707533F6337C2DDE_2018690759 by [email protected] @ 1_26_55 PM.wav" | sed -E 's/(.*)_[0-9].* by .*(\.wav)//'
/home/user/recordings/test/october/28D1E1840DE24D9DB4CF6D1A707533F6337C2DDE.wav
Com sed
, você salva partes de sua expressão com ()
e depois as coloca de volta com
.