I am writing a shell command to find files that end with .sh but display the name without the extension, for example :
file1.sh -> file
file2_sh.sh -> file2_sh
I wrote the following :
find . -name '*.sh' | tr '.sh' ' '
The outcome or the first example is :
file1.sh -> file
file2_sh.sh -> file2_
#here it should keep '_sh' but removes all ocurrences of sh
What should I do to keep the '_sh' and only remove the last occurence after the dot.
Thank you ver much
CodePudding user response:
tr '.sh' ' '
will replace every instance of s
, h
, or .
with a space. It does not care about grouping. You want something like:
find . -name '*.sh' | sed 's/\.sh$//'