LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 08-18-2016, 06:35 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Rename files


I have a group of files that are named as so.

4 digits, a space, then a dash, and another space ending with .txt.

I tried this,

Code:
rename -n 's/('0814 - ')//g' *txt
Quote:
Substitution pattern not terminated at (user-supplied code).
 
Old 08-18-2016, 07:52 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Try instead not relying on the quotes and instead delimiting the special characters with the backslash:
Code:
rename -n s/0814\ \-\ //g *.txt
 
Old 08-18-2016, 09:17 PM   #3
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
It did not work.

I need this renamed like so.

Quote:
0814 - test.txt > test.txt
 
Old 08-18-2016, 09:30 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I'll try to check it tomorrow when I'm back at my system, only have limited resources for now.
 
Old 08-19-2016, 08:00 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Done on Ubuntu 14.04:
Code:
$ ls -1
fm 1234 - test.txt
rt 1234 - test.txt
$ rename 's/1234\ \-\ test/test/g' *.txt
$ ls -1
fm test.txt
rt test.txt
$
 
Old 08-19-2016, 10:47 AM   #6
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
???


Quote:
andy@7:~/Downloads$ ls
0814 - test.txt Elementary Volunteer List August 2016.xls
BriggsStrattonQuickStart.pdf Pray_For_Me_Help_Sheet_Lesson6.pdf
andy@7:~/Downloads$ rename 's/1234\ \-\ test/test/g' *.txt
andy@7:~/Downloads$ ls
0814 - test.txt Elementary Volunteer List August 2016.xls
BriggsStrattonQuickStart.pdf Pray_For_Me_Help_Sheet_Lesson6.pdf
andy@7:~/Downloads$
 
Old 08-19-2016, 11:31 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
So you took my example, verbatim however I used "1234" versus "0814". You need to account for specific strings which are the ones you wish to match versus what my example shows. My example is a template to follow:
Code:
$ rename 's/0814\ \-\ //g' *.txt
Should work. What also should work is:
Code:
$ rename 's/0814\ \-\ test/test/g' *.txt
As I'm saying though, please be prepared to adapt those terms to file name strings applicable to the case at hand, otherwise just duplicating the exact string all the time is not going to work for you.
 
1 members found this post helpful.
Old 08-19-2016, 01:46 PM   #8
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Thanks, it works.

Sorry, I overlooked that. :-)
 
Old 08-20-2016, 02:34 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Fixit7 View Post
Sorry, I overlooked that. :-)
honestly i find that hard to believe.
Attached Thumbnails
Click image for larger version

Name:	scrot-2016-08-20_10:32:08-or8.png
Views:	172
Size:	18.5 KB
ID:	22803  
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Application to eliminate doubles in files and rename changed files with date? S. Chapelin Linux - Software 6 01-16-2011 02:02 AM
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 08:00 AM
get files from ftp and rename those files.. amaulana Linux - Newbie 2 11-15-2008 10:14 PM
how to rename files bkcreddy17 Programming 7 09-14-2008 09:22 AM
rename files allelopath Linux - General 5 07-05-2005 03:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 07:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration