Skip to main content
Fix quoting and tr link, also remove dups in tr string
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

If you don't mind losing the second -, another solution is using trtr:

x='Nora Hmann - sub-01.zip'
echoprintf $x'%s\n' "$x" | tr -d 'NoraHmann'NoraHmn -'
sub01.zip

Note this relies on the fact that the 'NoraHmanncharacters in the set 'NoraHmn -' string characters do not intersect with sub*.zip.

If you don't mind losing the second -, another solution is using tr:

x='Nora Hmann - sub-01.zip'
echo $x | tr -d 'NoraHmann -'
sub01.zip

Note this relies on the fact that the 'NoraHmann -' string characters do not intersect with sub*.zip.

If you don't mind losing the second -, another solution is using tr:

x='Nora Hmann - sub-01.zip'
printf '%s\n' "$x" | tr -d 'NoraHmn -'
sub01.zip

Note this relies on the fact that the characters in the set 'NoraHmn -' do not intersect with sub*.zip.

Source Link
Lee
  • 549
  • 4
  • 7
  • 18

If you don't mind losing the second -, another solution is using tr:

x='Nora Hmann - sub-01.zip'
echo $x | tr -d 'NoraHmann -'
sub01.zip

Note this relies on the fact that the 'NoraHmann -' string characters do not intersect with sub*.zip.