Reputation: 16029
How can I remove a specific filename extension in the filename in a directory using sed. Like for example I have a files in a directory,
file1.txt
file2.txt
file3.cpp
Then I want to remove the filename extension of a file with .txt extension, so the result is,
file1
file2
file3.cpp
Thanks!
Upvotes: 0
Views: 2126
Reputation: 4602
And if you really want to use sed, this should work:
for file in *.txt ; do mv $file `echo $file | sed 's/\(.*\)\.txt/\1/'` ; done
Upvotes: 1
Reputation: 123458
You can use rename
:
rename 's/\.txt$//' *
Saying so would remove the .txt
extension from matching files.
Upvotes: 2