Tuesday, October 4, 2022

[SOLVED] Removing part of the file names

Issue

I have a bunch of files like this:

file123.txt.452
file456.txt.098
file789.txt.078

How can I remove the second dot and the numbers at the end from the file names?

I tried using rename but I don’t think my regex is correct:

rename 's/txt.*/txt/' *

Solution

Something like:

for f in *.txt.*; do
    g=${f%.txt.*}.txt
    mv $f $g
done


Answered By - Maxim Egorushkin
Answer Checked By - Clifford M. (WPSolving Volunteer)