Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 3818  / 1 Year ago, sat, december 24, 2022, 4:51:00

I have a bunch of .txt files in a directory, and I want to be able to find these files and strip the extension from the file name.


I can find the files using:


$ find . -maxdepth 1 -type f -name "*.txt"
./0test.txt
./1test.txt
./2test.txt
./3test.txt
./4test.txt
./5test.txt
./6test.txt
./7test.txt
./8test.txt
./9test.txt

I then tried to use sed command to remove the ".txt" extension, like:


find . -maxdepth 1 -type f -name "*.txt" | sed "s/.txt$//"

But I just get the file names listed without their extensions, and the actual file names remain unchanged.


So how do you actually change the file names themselves?


More From » 20.04

 Answers
5

How about this in bash


for v in *.txt ; do mv "$v"  "$(basename "$v" .txt)"; done

[#1569] Sunday, December 25, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oileweaty

Total Points: 337
Total Questions: 108
Total Answers: 105

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
;