rename more files special case


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers rename more files special case
# 1  
Old 09-25-2008
rename more files special case

hello all

i have a big problems for me

if i have more files as example

test.ghrt.part01.rar
test.ghrt.part02.rar
test.ghrt.part03.rar
test.ghrt.part04.rar
test.ghrt.part05.rar
test.ghrt.part06.rar
test.ghrt.part07.rar
test.ghrt.part08.rar
test.ghrt.part09.rar
test.ghrt.part10.rar
test.ghrt.part11.rar

and i need to rename it to

mail.ghrt.part01.rar
mail.ghrt.part02.rar
mail.ghrt.part03.rar
mail.ghrt.part04.rar
mail.ghrt.part05.rar
mail.ghrt.part06.rar
mail.ghrt.part07.rar
mail.ghrt.part08.rar
mail.ghrt.part09.rar
mail.ghrt.part10.rar
mail.ghrt.part11.rar

how can i do this

thanks for your cooperation
# 2  
Old 09-25-2008
no any replay
# 3  
Old 09-25-2008
Quote:
for i in `ls -1 test.ghrt*`
do
new=`echo $i|sed 's/\(^test\)\(.*\)/mail\2/g'`
mv $i $new
done
this will do.. you can optimize it using awk..
# 4  
Old 09-25-2008
really that is very good

it's solve my problems


can you explain it for me
# 5  
Old 09-25-2008
The ls in backticks is Useless. The sed and echo can be replaced with a variable substitution. Variables should be double-quoted although it doesn't really matter in this case if the example file names are representative.

Code:
for i in test.ghrt*; do
  mv "$i" mail."${i#test.}"
done

The expression ${var#subst} evaluates to the value of $var with the prefix subst removed (if matched). There are other similar operations for suffix substitution etc; see the shell's manual page or a tutorial for details.

Last edited by era; 09-25-2008 at 01:45 AM.. Reason: Attempt to explain ${var#subst}
# 6  
Old 09-25-2008
Quote:
Originally Posted by ateya
how can i do this
if you have Python, here's a script you can use:
eg usage:
Code:
# ls -1 test.gh*
test.ghrt.part01.rar
test.ghrt.part02.rar

# filerenamer.py -p "test" -e "mail" -l "test.ghrt*" #use -l to list
==>>>>  [ /home/test.ghrt.part01.rar ]==>[ /home/mail.ghrt.part01.rar ]
==>>>>  [ /home/test.ghrt.part02.rar ]==>[ /home/mail.ghrt.part02.rar ]

# filerenamer.py -p "test" -e "mail"  "test.ghrt*" #remove -l to commit
/home/test.ghrt.part01.rar  is renamed to  /home/mail.ghrt.part01.rar
/home/test.ghrt.part02.rar  is renamed to  /home/mail.ghrt.part02.rar

# ls -1 test.gh*
/bin/ls: test.gh*: No such file or directory

# ls -1 mail.gh*
mail.ghrt.part01.rar
mail.ghrt.part02.rar

# 7  
Old 09-25-2008
thanks for all

really thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename File Name with Special Characters

I am trying to rename files with spaces and other characters and not able to be successful. FileNames: UPLOAD REFERENCE.xls UPLOAD MASS REFERENCE.XLS find /UPLOAD REFERENCE/ -depth -type f -name "* *" -exec rename " " "_" "{}" ";" The above one is successful to replace spaces... (1 Reply)
Discussion started by: eskay
1 Replies

2. Shell Programming and Scripting

Special case to skip function in bash menu

In the bash menu below if the variant that is inputted is in the format NM_004004.3:c.274G>T the below works perfectly. My question is if the variant inputted isNM_004004.3:-c.274G>T or NM_004004.3:+c.274G>T then the code as is will throw an error due to a biological issue. Is it possible to to... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

awk special parse case

I have a special case that awk could be used but I do not have the skill. Trying to create a final output file (indel_parse.txt) that is created from using some information from each of the two files (attached). parse rules: The header is skipped FNR>1 1. 4 zeros after the NC_ (not... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Rename file of special type

HI ! all till date I usually rename file like this n=201108290000 for file in *.nc; do file_name=M.m.1.1.1.$n.ready n=$(( $n+1 )) mv $file $file_name donebut in this case I have to rename file depending on basename of file, when I list files results like this, if there is leap... (6 Replies)
Discussion started by: Akshay Hegde
6 Replies

5. Shell Programming and Scripting

Row to columns - special case

Hi. Let me start saying that i am kinda new to bash, and have few skills in programming. I've been advised to use bash to manipulate large .csv files. I've been able to do some data filtering using fors, grep and tail commands. That was kinda easy seeing examples. But now i need to do some hard... (1 Reply)
Discussion started by: jmarmitt
1 Replies

6. Shell Programming and Scripting

Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu. But i must control their input. These are criteria: Input must have 4 signs First two signs are always lower case letters Input shall not have some special signs just letters and numbers ... (1 Reply)
Discussion started by: waso
1 Replies

7. Shell Programming and Scripting

Rename files and directories with special characters

Hello guys, I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that? Thanks for the help. AV (0 Replies)
Discussion started by: avatar_007
0 Replies

8. UNIX for Dummies Questions & Answers

Shell script to rename or change file extension case.

I searched the forum, but there was different type of rename. Hello. I have files in folder. Like: xxxxxxxx1.html or xxxxxxxx2.txt or xxxxxxxx3.tar.gz and how to rename or change file extension case to xxxxxxxx1.htm or xxxxxxx2.TXT or (5 Replies)
Discussion started by: Sheldon
5 Replies

9. SCO

Avoiding duplicates with some special case

Hi Gurus, I had a question regarding avoiding duplicates.i have a file abc.txt abc.txt ------- READER_1_1_1> HIER_28056 XML Reader: Error occurred while parsing:; line number ; column number READER_1_3_1> Sun Mar 23 23:52:48 2008 READER_1_3_1> HIER_28056 XML Reader: Error occurred while... (0 Replies)
Discussion started by: pssandeep
0 Replies

10. UNIX for Dummies Questions & Answers

how to delete whole directory in special case

Hello, Today, as a root user, i want to copy recursively all files and diretories in a source directory to a destination directory using the following command, cp -r /home/smith/* /home/bob/ However, I carelessly missed the '*' out when I executed the command. Now, i noticed a... (1 Reply)
Discussion started by: cy163
1 Replies
Login or Register to Ask a Question