Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am good in excel so till now doing with excel but now data is too hugh,more than 8 crore records. So its difucult to downlaod gb's of data of rename the files.
Need to rename few files as
Source filename to destination filename (Vice-versa)
52776631_1_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_1.pk
52776631_2_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_2.pk
52776631_3_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_3.pk
52776631_4_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_4.pk
52776631_5_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_5.pk
52776631_6_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_6.pk
52776631_7_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_7.pk
52776631_8_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_8.pk
52776631_9_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_9.pk
52776631_10_fingerprints_555_13630002_0046_00098555_N.bmp to 52776631_fp_10.pk

_fingerprints_555_13630002_0046_00098555_N.bmp Will be constant for all records.


And then vice-versa.
Environment: Redhat Linux.
Please help me out.Thanks in advance.
Posted

1 solution

awk is a very powerful tool. I advice you to use it.

ls *.bmp | awk -F"_" '{ print $0" "$1"_fp_"$2".pk" }'  | while read a b
do
  mv $a $b
done
 
Share this answer
 
Comments
CPallini 19-Jan-14 8:07am    
I agree.
Sanjeev236 20-Jan-14 9:37am    
Vedat: You are Genius,resolved my problem very efficiently.
Now i am trying to convert vice-versa myself.
Thank You.
Vedat Ozan Oner 20-Jan-14 9:51am    
You are welcome :)
Sanjeev236 20-Jan-14 11:02am    
Dear Vedat,

i tried for vice versa means from 52776631_fp_1.pk to 52776631_1_fingerprints_555_13630002_0046_00098555_N.pk. Script I modofied is as:
ls *.pk | awk -F"_" '{ print $0" "$1"_"$3"_fingerprints_555_13630002_0046_00098555_N.pk" }' | while read a b
do
mv $a $b
done
=================
incorrect result arises is as:
52776631_9.pk_fingerprints_555_13630002_0046_00098555_N.pk

Please suggest the required changes.Thanks in advance.
Vedat Ozan Oner 20-Jan-14 11:37am    
change 'ls *.pk' according to your needs. before renaming, see what awk prints.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900