Renaming file that has multiple numbers as filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming file that has multiple numbers as filename
# 1  
Old 02-25-2013
Renaming file that has multiple numbers as filename

Hi
I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798"

Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org"

i tried with
Code:
#  ls | grep -E "partition-setup-and-ipl.vtcmd.[0-9]+"
partition-setup-and-ipl.vtcmd.76217657132.9721536798
# mv partition-setup-and-ipl.vtcmd.[0-9]+ partition-setup-and-ipl.vtcmd.[0-9]+_org
mv: cannot rename partition-setup-and-ipl.vtcmd.[0-9]+ to partition-setup-and-ipl.vtcmd.[0-9]+_org:
No such file or directory

I feel i miss something in regular expression.. Please Help Smilie
# 2  
Old 02-25-2013
You don't - you fell for one of the illogicalities in *nixes. grep uses regex pattern matching with char repetition tokens, while the shell offers sth. called globbing using less versatile wild cards.
Read your shell's man page on how you need to compose a correct pattern.
# 3  
Old 02-25-2013
1st trap:
ERE (grep -E or egrep) matches versus glob (wildcard) matches. As RudiC pointed out.
2nd trap:
the shell matches the wildcards against existing files in the current directory.
So the destination cannot be matched.
A way out is a loop, either
Code:
ls | grep -E "partition-setup-and-ipl.vtcmd.[0-9]+" |
while read file
do
 mv "$file" "$file"_org
done

Or
Code:
for file in partition-setup-and-ipl.vtcmd.[0-9]*[0-9]
do
 mv "$file" "$file"_org
done

While the latter is not as precice, because * allows all characters after the [0-9],
I added another [0-9] so at least it does not match the _org files.

Last edited by MadeInGermany; 02-25-2013 at 08:04 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

2. Shell Programming and Scripting

Splitting file into multiple files and renaming them

Hi all, Newbie here. First of all, sorry if I made any mistakes while posting this question in terms of rules. Correct me if I am wrong. :b: I have a .dat file whose name is in the format of 20170311_abc_xyz.dat. The file consists of records whose first column consists of multiple dates in... (2 Replies)
Discussion started by: chanduris
2 Replies

3. Shell Programming and Scripting

Multiple File renaming with a twist

Hi I can do simple file renaming but this task is slightly more troublesome Ive got a guy that gives me multiple .pdf filles in a directory named something like 3412345.pdf 4565465.pdf 8534534.pdf And he also gives me a html file which is tabled with which shows the filenames above... (2 Replies)
Discussion started by: messiah1
2 Replies

4. Shell Programming and Scripting

Renaming multiple files at once (discarding suffix of the filename after a character)

Hi, I have a lot of files similar to the below order. I want to rename all the files .discrading the time stamp/numbers after cnf. Existing files id_info_20130405.cnf_20130801 in_info_20130405.cnf_20130891 iz_info_20130405.cnf_20130821 in_info_20130405.cnf_20130818... (2 Replies)
Discussion started by: saravanapandi
2 Replies

5. Shell Programming and Scripting

Renaming a filename

Hi friends , i want to change the filename as below filename=ABC_HYND_JDHD_20130125120345.txt expected output : ABC_HYND_JDHD_20130125.txt i have tried using awk but not able to procedd futher. i am trying to do the above in single commad. echo... (3 Replies)
Discussion started by: i150371485
3 Replies

6. Shell Programming and Scripting

increase/decrease multiple numbers in a filename.

I got a game that output map tiles of the session with the 0,0 position at the place you login/spawn. That makes making a map somewhat troublesome since the 0,0 will move. So I've been looking for a way to change the numbers in the filenames of all files in a folder by a certain value. The... (5 Replies)
Discussion started by: Ravenholdt
5 Replies

7. Shell Programming and Scripting

Renaming the filename

Hi, I have several files with name b1.root, b2.root b3.root I want to rename the "b" to "bkg", so finally is should be: bkg1.root bkg2.root bkg3.root I used command: rename s/b/bsig/ b*root Somehow it is working at some place and not working in other folder. I do not have any idea... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

8. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

9. UNIX for Dummies Questions & Answers

Multiple file renaming

Hi All, I have a number of files in a directory that I would like to rename - I am quite aware that you can use the mv command to rename the files - I would like to rename them automatically from the command line instead of having to do them singly. I have searched the forum pertaining to... (4 Replies)
Discussion started by: BigTool4u2
4 Replies

10. UNIX for Dummies Questions & Answers

renaming a compressed file to filename without .Z

In a shell script I would like to use a compressed file name, i.e. with suffix of .Z, as a file input $1. After the file in uncompressed, I would like to use the file name without the .Z . How do I do this? Thank you. (8 Replies)
Discussion started by: bruceps
8 Replies
Login or Register to Ask a Question