Renaming Files With 2 .


 
Thread Tools Search this Thread
# 8  
Quote:
Originally Posted by otheus
Code:
mv cob120514093156.03.466926330  cob120514093156.03.466926330.bd 
mv CCBS-CPMM_SEND_COB_120514_100549_3.rpt cob120514093156.03.466926330.br

thx bro for the info...
but this will done if only i got 1 files to rename...

---------- Post updated at 04:37 PM ---------- Previous update was at 04:37 PM ----------

Quote:
Originally Posted by radoulov
Threads merged.
thx bro...

---------- Post updated 05-22-12 at 09:53 AM ---------- Previous update was 05-21-12 at 04:37 PM ----------

anybody can help?
# 9  
Please explain your requirement clearly ..
# 10  
try this for bash...

Code:
#!/bin/bash

for br in *.rpt; do
        IFS=_. read -ra a <<< "$br"
        bd=( cob*${a[3]}*.0${a[5]}.* )
        [[ -f $bd ]] || continue
        echo mv "$br" "$bd.br"
        echo mv "$bd" "$bd.bd"
done

Code:
[mute@geek ~/temp/yokomo]$ ./script
mv CCBS-CPMM_SEND_COB_120504_164036_3.rpt cob120504160145.03.463632893.br
mv cob120504160145.03.463632893 cob120504160145.03.463632893.bd
mv CCBS-CPMM_SEND_COB_120504_173434_6.rpt cob120504165132.06.463647479.br
mv cob120504165132.06.463647479 cob120504165132.06.463647479.bd
mv CCBS-CPMM_SEND_COB_120509_105932_3.rpt cob120509102642.03.465240413.br
mv cob120509102642.03.465240413 cob120509102642.03.465240413.bd
mv CCBS-CPMM_SEND_COB_120509_113801_6.rpt cob120509111109.06.465251277.br
mv cob120509111109.06.465251277 cob120509111109.06.465251277.bd
mv CCBS-CPMM_SEND_COB_120514_100549_3.rpt cob120514093156.03.466926330.br
mv cob120514093156.03.466926330 cob120514093156.03.466926330.bd
mv CCBS-CPMM_SEND_COB_120514_105431_6.rpt cob120514101600.06.466934894.br
mv cob120514101600.06.466934894 cob120514101600.06.466934894.bd
mv CCBS-CPMM_SEND_COB_120520_071123_3.rpt cob120520062034.03.468862192.br
mv cob120520062034.03.468862192 cob120520062034.03.468862192.bd
mv CCBS-CPMM_SEND_COB_120520_093606_6.rpt cob120520084640.06.468886464.br
mv cob120520084640.06.468886464 cob120520084640.06.468886464.bd

of course remove the 'echo' in front of 'mv' if the output seems OK.
# 11  
Quote:
Originally Posted by neutronscott
try this for bash...

Code:
#!/bin/bash

for br in *.rpt; do
        IFS=_. read -ra a <<< "$br"
        bd=( cob*${a[3]}*.0${a[5]}.* )
        [[ -f $bd ]] || continue
        echo mv "$br" "$bd.br"
        echo mv "$bd" "$bd.bd"
done

Code:
[mute@geek ~/temp/yokomo]$ ./script
mv CCBS-CPMM_SEND_COB_120504_164036_3.rpt cob120504160145.03.463632893.br
mv cob120504160145.03.463632893 cob120504160145.03.463632893.bd
mv CCBS-CPMM_SEND_COB_120504_173434_6.rpt cob120504165132.06.463647479.br
mv cob120504165132.06.463647479 cob120504165132.06.463647479.bd
mv CCBS-CPMM_SEND_COB_120509_105932_3.rpt cob120509102642.03.465240413.br
mv cob120509102642.03.465240413 cob120509102642.03.465240413.bd
mv CCBS-CPMM_SEND_COB_120509_113801_6.rpt cob120509111109.06.465251277.br
mv cob120509111109.06.465251277 cob120509111109.06.465251277.bd
mv CCBS-CPMM_SEND_COB_120514_100549_3.rpt cob120514093156.03.466926330.br
mv cob120514093156.03.466926330 cob120514093156.03.466926330.bd
mv CCBS-CPMM_SEND_COB_120514_105431_6.rpt cob120514101600.06.466934894.br
mv cob120514101600.06.466934894 cob120514101600.06.466934894.bd
mv CCBS-CPMM_SEND_COB_120520_071123_3.rpt cob120520062034.03.468862192.br
mv cob120520062034.03.468862192 cob120520062034.03.468862192.bd
mv CCBS-CPMM_SEND_COB_120520_093606_6.rpt cob120520084640.06.468886464.br
mv cob120520084640.06.468886464 cob120520084640.06.468886464.bd

of course remove the 'echo' in front of 'mv' if the output seems OK.

neutronscott... it return error like this... (newscript.sh[3]: Syntax error at line 4 : `<' is not expected.
)
# 12  
it's a bash script. did you use "sh newscript.sh". if you don't have bash available, maybe I'll try a rewrite tomorrow. what shell do you use?
# 13  
Quote:
Originally Posted by neutronscott
it's a bash script. did you use "sh newscript.sh". if you don't have bash available, maybe I'll try a rewrite tomorrow. what shell do you use?
yes... i use the sh newscript.sh...
shell type :- /usr/bin/csh
Version :- HP-UX B.11.11 9000/800
# 14  
no sane person would script csh Smilie
i am not experienced with commercial versions. this should work with older ksh.
use "ksh script" or just chmod a+x script; ./script
Code:
#!/usr/bin/ksh

for br in *.rpt; do
        id1=${br##*_COB_}
        id2=${id1%.rpt}
        id2=${id2##*_}
        id1=${id1%%_*}
        bd=( cob*${id1}*.0${id2}.* )
        [[ -f "$bd" ]] || continue
        echo mv "$br" "$bd.br"
        echo mv "$bd" "$bd.bd"
done


Last edited by neutronscott; 05-22-2012 at 11:07 AM..
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. UNIX for Dummies Questions & Answers

Help with renaming the files.

Hi, I have 31 file as below.... dt_ref_med_merged_madt_h_19980101.nc .. .. dt_ref_med_merged_madt_h_19980131.nc I want to rename it like... dt_ref_med_merged_madt_h_1998_1.nc .. .. dt_ref_med_merged_madt_h_1998_31.nc How can I do it ? any suggestions ? I want to do it small... (5 Replies)
Discussion started by: mahesh shinde
5 Replies

3. UNIX for Dummies Questions & Answers

Renaming Files

I just used wget to obtain a bunch of html documents. Now they are named index.html, index.html.1, index.html.2, etc. I'd simply like to move the 1, 2, 3 etc. to the left before the .html, so the new names would be: index1.html, index2.html etc. I know this can be done with a simple script, but... (2 Replies)
Discussion started by: crl21
2 Replies

4. Shell Programming and Scripting

Renaming files

Can someone please help. Much appreciated!! I have 4 directories, for ex... /RUN1/ReportTable.nxt /RUN2/ReportTable.nxt /RUN3/ReportTable.nxt /RUN4/ReportTable.nxt I would like to write a for loop, to add the directory name to each ReportTable.nxt I would like for it to be: ... (5 Replies)
Discussion started by: dirttysoufff
5 Replies

5. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

6. UNIX for Dummies Questions & Answers

renaming all files

requirement: There are many files inside a directory and all are named like this "out_1". The file names goes on itearation like out_2, out_3 etc.... Now i want to rename all the file names based on the text inside the file. the text in all the files follow a pattern like it satrts... (4 Replies)
Discussion started by: arunmanas
4 Replies

7. Shell Programming and Scripting

Renaming the files

Hello, i wanna rename my files which names are written in movies.txt films.txt = amovie bmovie cmovie dmovie emovie and i wanna find this files and rename the files to 1_amovie ... (12 Replies)
Discussion started by: redbeard_06
12 Replies

8. Shell Programming and Scripting

renaming Files

Renaming Files more than 1000 in Diffrent Directories in system.. help me in this issue to resolve.... (5 Replies)
Discussion started by: sunsap
5 Replies

9. Shell Programming and Scripting

Renaming files

Hello. Need to rename 1000's of files with names like 991%20(2003)%20-%20991%20Ryall%20Prison%20Population%20and%20Recorded%20Crime.doc All I need is the beginning numbers , in this case 991 . Tried: for file in * ; do mv $file `echo $file | sed '/^{p;q}'` ; done but no luck. Thank... (8 Replies)
Discussion started by: whatsup
8 Replies

10. UNIX for Dummies Questions & Answers

renaming the files

Hi All, Today I got a small problem while handling zipped files in PROD support. There are files in this format and I had to grep them reading some contents A.B.gz.C.D where A,B,C and D stand for variables (like FIRST.NAME.gz.MIDDLE.LAST). I know that these files are zipped files and If I... (1 Reply)
Discussion started by: adurga
1 Replies

Featured Tech Videos