6

Tip #670   Clean a string for a filename

The command below can be used to convert a string into a valid filename. Uppercase letters are converted to lowercase, all difficult characters are removed and spaces are changed to underscores.

echo "#cLEa:n (%FILE%)" | tr [:upper:] [:lower:] | tr -d "[]()&~@#%^&*()_+=;:,\$" | tr " " "_"

This example will output 'clean_file'.
 
  • TAGS:
  • tr