1 |
On Mon, Jul 02, 2007 at 09:59:17PM +0100, Penguin Lover Mick squawked: |
2 |
> Hi All, |
3 |
> |
4 |
> I backed up my wife's WinXP fs using K3B and I used default settings which |
5 |
> unfortunately converted all file names to CAPITALS and shortened them to 8 |
6 |
> characters maximum, just like DOS would do. Is there a clever way to change |
7 |
> some of them back to lower case (in batches within given directorates) so |
8 |
> that she doesn't have to do it manually one by one? I do not want to change |
9 |
> the access times, only the filename case letters. |
10 |
|
11 |
from 'info sed' -> Examples |
12 |
|
13 |
#! /bin/sh |
14 |
# rename files to lower/upper case... |
15 |
# |
16 |
# usage: |
17 |
# move-to-lower * |
18 |
# move-to-upper * |
19 |
# or |
20 |
# move-to-lower -R . |
21 |
# move-to-upper -R . |
22 |
# |
23 |
|
24 |
help() |
25 |
{ |
26 |
cat << eof |
27 |
Usage: $0 [-n] [-r] [-h] files... |
28 |
|
29 |
-n do nothing, only see what would be done |
30 |
-R recursive (use find) |
31 |
-h this message |
32 |
files files to remap to lower case |
33 |
|
34 |
Examples: |
35 |
$0 -n * (see if everything is ok, then...) |
36 |
$0 * |
37 |
|
38 |
$0 -R . |
39 |
|
40 |
eof |
41 |
} |
42 |
|
43 |
apply_cmd='sh' |
44 |
finder='echo "$@" | tr " " "\n"' |
45 |
files_only= |
46 |
|
47 |
while : |
48 |
do |
49 |
case "$1" in |
50 |
-n) apply_cmd='cat' ;; |
51 |
-R) finder='find "$@" -type f';; |
52 |
-h) help ; exit 1 ;; |
53 |
*) break ;; |
54 |
esac |
55 |
shift |
56 |
done |
57 |
|
58 |
if [ -z "$1" ]; then |
59 |
echo Usage: $0 [-h] [-n] [-r] files... |
60 |
exit 1 |
61 |
fi |
62 |
|
63 |
LOWER='abcdefghijklmnopqrstuvwxyz' |
64 |
UPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
65 |
|
66 |
case `basename $0` in |
67 |
*upper*) TO=$UPPER; FROM=$LOWER ;; |
68 |
*) FROM=$UPPER; TO=$LOWER ;; |
69 |
esac |
70 |
|
71 |
eval $finder | sed -n ' |
72 |
|
73 |
# remove all trailing slashes |
74 |
s/\/*$// |
75 |
|
76 |
# add ./ if there is no path, only a filename |
77 |
/\//! s/^/.\// |
78 |
|
79 |
# save path+filename |
80 |
h |
81 |
|
82 |
# remove path |
83 |
s/.*\/// |
84 |
|
85 |
# do conversion only on filename |
86 |
y/'$FROM'/'$TO'/ |
87 |
|
88 |
# now line contains original path+file, while |
89 |
# hold space contains the new filename |
90 |
x |
91 |
|
92 |
# add converted file name to line, which now contains |
93 |
# path/file-name\nconverted-file-name |
94 |
G |
95 |
|
96 |
# check if converted file name is equal to original file name, |
97 |
# if it is, do not print nothing |
98 |
/^.*\/\(.*\)\n\1/b |
99 |
|
100 |
# now, transform path/fromfile\n, into |
101 |
# mv path/fromfile path/tofile and print it |
102 |
s/^\(.*\/\)\(.*\)\n\(.*\)$/mv "\1\2" "\1\3"/p |
103 |
|
104 |
' | $apply_cmd |
105 |
|
106 |
|
107 |
|
108 |
..... which is probably a bit of an overkill. |
109 |
(And don't ask me why I remember this particular example being in the |
110 |
sed info page ;p ) |
111 |
|
112 |
HTH, |
113 |
|
114 |
W |
115 |
|
116 |
|
117 |
-- |
118 |
"`The best way to get a drink out of a Vogon is to stick |
119 |
your finger down his throat...'" |
120 |
|
121 |
- The Book, on one of the Vogon's social inadequacies. |
122 |
Sortir en Pantoufles: up 206 days, 20:29 |
123 |
-- |
124 |
gentoo-user@g.o mailing list |