trying to rename the files in dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to rename the files in dir
# 1  
Old 07-02-2007
trying to rename the files in dir

I have bunch of files in win xp machine with

123456 E15 filename
112333.E20 filename
123412.E11 filename

you get the pic, I mount that xp machine's share into linux and try to do a mass rename to something simpler

E15 filename
E20 filename and so on..

I wrote below thinking that it would work but it does not.. can someone advise?

#!/bin/sh
ls |
egrep "^[0-9][0-9][0-9][0-9][0-9]" |
while read a
do
echo $a
yahoo=`sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi'`
mv $a $yahoo ; mv $yahoo $a
done
# 2  
Old 07-02-2007
yahoo=`sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi'`

You're not giving sed any input. You need to echo $a into it or something like that. But then it looks like your two mv statement cancel each other. Smilie I don't really understand your script.
# 3  
Old 07-02-2007
Quote:
Originally Posted by hankooknara
I have bunch of files in win xp machine with

123456 E15 filename
112333.E20 filename
123412.E11 filename

you get the pic, I mount that xp machine's share into linux and try to do a mass rename to something simpler

E15 filename
E20 filename and so on..
[...]
Assuming the first filename is 123456.E15 filename and not 123456 E15 filename, with zsh:

Code:
autoload -U zmv
zmv '[0-9]*.(*)' '$1'

# 4  
Old 07-02-2007
I guess below is what I try to do.. and does it make sense?

trying to rename a file.. so i guess mv $a $yahoo is ok?

and yes some file has 6 digits following by space or .



Code:
#!/bin/sh
ls |
    egrep "^[0-9][0-9][0-9][0-9][0-9]" |
     while read a
      do
         yahoo=`echo $a |sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi'`
         mv $a $yahoo  
done

# 5  
Old 07-02-2007
Below code seem to work..

070625 kbs1.E41.You.Landscape.kor.hdtv.original.avi

was the original file name I did test on..


Code:
#!/bin/sh
ls |
    egrep "^[0-9][0-9][0-9][0-9][0-9]" |
     while read a
      do
         yahoo=`echo $a |sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi'`
         echo $yahoo
         mv "$a" "$yahoo"
done

Now I am trying to modify that so it will take out kbs1,

other file might have

mbc,sbs,kbs,kbs1 mbc1 mbc2 kbs2 but below did not work

Code:
#!/bin/sh
ls |
    egrep "^[0-9][0-9][0-9][0-9][0-9]" |
     while read a
      do
         yahoo=`echo $a |sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi' | sed 's/^[kms]b[sc][12]?//gi`
         echo $yahoo
         mv "$a" "$yahoo"
done

# 6  
Old 07-02-2007
I think below works.. I guess + is not supported under sed..

I am bit nervous to run below command on folder that I have so many avi files.. I don't want to wreck anything up.. does anyone see any danger?

Code:
#!/bin/sh
ls |
    egrep "^[0-9][0-9][0-9][0-9][0-9]" |
     while read a
      do
         yahoo=`echo $a |sed 's/^[0-9][0-9][0-9][0-9][0-9][0-9][ .]//gi' | sed 's/^[kms]b[cs][^.]*\.//gi'`
         echo $yahoo
         mv "$a" "$yahoo"
done

# 7  
Old 07-02-2007
I would first do:

echo mv "$a" "$yahoo"

and then look at the output to be sure. And I would have a backup so I can recover if it fumbles.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Loop through the dir and Rename zip files and their underlying text file.

I have files in the ABC_YYYYMMDD.zip format under a directory. Each zip file contains A text file in the ABC_YYYYMMDD.txt format. I am trying to create a script that will Rename the zip files and their underlying text file replacing the datepart in them with . For eg: in the case of... (1 Reply)
Discussion started by: bash987
1 Replies

3. Shell Programming and Scripting

Script to move all files in a dir into a certain dir

Hello all, I'm very new to shell scripting and need quite urgently to do this thing for my student job. I have a directory called "vectors" with a bunch of files all named ".vector". also i have for each of those files a directory with the name . I now want to move each of those *.vector files... (2 Replies)
Discussion started by: sherresh
2 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

7. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. Shell Programming and Scripting

Rename a file after the name of its parent dir

Started a thread in beginners but I thought someone from this forum may have an idea as well. Thanks! EDITED BY REBORG (3 Replies)
Discussion started by: robotsbite
3 Replies

9. Windows & DOS: Issues & Discussions

DOS script to grab the first file in a dir and rename it

:confused: Hello, Is there any way to use the dir command / some DOS Script to select only first file of similar pattern of files in a direcotory and rename it for example, one directory has 5 files abc_1005.txt abc_5256.txt abc_2001.txt abc_2003.txt abc_3006.txt by use script I would... (2 Replies)
Discussion started by: raghav525
2 Replies

10. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies
Login or Register to Ask a Question