Renaming batch by removing substring


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 6 Days Ago
Renaming batch by removing substring

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

Currently I have

Code:
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
Code:
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
# 2  
Old 6 Days Ago
bash:
Code:
for f in *.tex.txt
do mv ${f} ${f/.tex/}
done

More Posix compliant (I believe):
Code:
for f in *.tex.txt
do mv ${f} ${f%.tex*}.txt
done

Andrew
This User Gave Thanks to apmcd47 For This Post:
Xubuntu56 (5 Days Ago)
# 3  
Old 6 Days Ago
Ubuntu should have rename(a perl script) available and installed:


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

This User Gave Thanks to stomp For This Post:
Xubuntu56 (5 Days Ago)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Script for batch renaming yifangt Shell Programming and Scripting 6 11-06-2015 10:35 AM
Shell Script Help..Renaming Quoted files removing the timestamp khman Shell Programming and Scripting 17 11-06-2015 05:54 AM
SFTP batch not renaming file with "put" dbiggied Shell Programming and Scripting 4 01-19-2015 04:41 PM
Renaming file in batch mfaizan40 Shell Programming and Scripting 9 12-24-2014 05:00 AM
Renaming Multiple Files by removing characters pchegoor UNIX for Dummies Questions & Answers 2 08-25-2014 10:50 PM
Need help in batch renaming files with bash shell script. SriRamKrish Shell Programming and Scripting 5 08-19-2014 11:46 AM
BASH Batch renaming insert additional zero into filename putter1900 Shell Programming and Scripting 3 04-16-2012 08:56 AM
script for renaming a batch of files shabs1985 Shell Programming and Scripting 3 08-09-2010 04:32 AM
Batch Renaming of Files gratefulhokie UNIX for Dummies Questions & Answers 8 01-19-2010 01:01 PM
batch renaming ... OneDreamCloser Shell Programming and Scripting 4 09-23-2009 08:55 PM
Removing prefix from multiple files and renaming file extension empyrean UNIX for Dummies Questions & Answers 3 06-10-2009 10:01 AM
removing items from a file with batch amir07 Shell Programming and Scripting 5 11-10-2008 02:51 PM
Batch Renaming: Change files' extensions in many sub-directories dave920 UNIX for Dummies Questions & Answers 10 07-21-2008 12:00 AM
simple batch renaming...45-*.php to 46-*.php bcamp1973 UNIX for Dummies Questions & Answers 2 11-01-2006 09:51 AM
Removing substring from a string dmilks Shell Programming and Scripting 1 07-28-2005 03:32 PM