Renaming batch by removing substring

I wish to rename all files ending in .txt by removing .tex .

Currently I have

me@me-Inspiron-518:~$ ls
 a.tex.txt   bin   b.tex.txt   c.tex.txt   Desktop   Documents   Downloads   d.tex.txt   Music   Pictures   Public   Templates   Videos

Desired outcome

me@me-Inspiron-518:~$ ls
  a.txt   bin   b.txt   c.txt   Desktop   Documents   Downloads   d.txt   Music   Pictures   Public   Templates   Videos

I can print to stdout with echo *.txt | sed 's/.tex//g' but it doesn't rename the files.

Ubuntu 18.04.2; Xfce 4.12.3; kernel 4.15.0-45-generic; bash 4.4.19(1); Dell Inspiron-518

bash:

for f in *.tex.txt
do mv ${f} ${f/.tex/}
done

More Posix compliant (I believe):

for f in *.tex.txt
do mv ${f} ${f%.tex*}.txt
done

Andrew

1 Like

Ubuntu should have rename (a perl script) available and installed:

rename 's/(.*).tex.txt/$1.txt/' *.txt
1 Like