solution tested Re: Filename character translation



On 2009-06-20, Tim Harig <usernet@xxxxxxxxxx> wrote:
On 2009-06-20, Deepan MYSQL <deepan.17@xxxxxxxxx> wrote:
how to change the first character of a filename alone?
ex:- from abc to Abc
I am assuming you want to capitalize the first letter in the the name of a
group of files. You could do something like (untested):

The solution seems to work as given; but, mv does whine to stderr when
given files that do not begin with lowercase letters and thus have the same
name. You can fix this by inserting a conditional.

For my test I created sample files using a python script that I have which
is designed to generate words from random letters that look something
similiar to human sentences (I originally used this for generating morse
practice code.)

Adding the conditional, my test looks like:

13:00,583$ ls
0hkf1te i7gxo15xvk ej6m4zmqz nbt jhjbvrdny qsiavdube 6jb9ej m0m4ktxnsi
2t1 5ugh z 0eip 85fwvxlebl2 ummokk r keoh7oy 8owjvqck3
4pq88o ombkr2zc duoeq3 irn4lpy ghj0qu c5yuos
6ej7gk v vn7fe5ae y 0hp9memhlk8 rucarvdj osfyx 9
7fsubxehovk uwdn9r sc u yvkrkwp kkqzyh rshquitc 1phhx2c
9yadyp hbz lu9 phvciwjigob x3y6d
b9ampeatph apzce mul1n 88d2cyj 6zsadjjwz zz6ydll 4zr1fckvceg uftxhh
m5xacr8b
dbadgaoij yvvac mb0 vjidb0 dsclv 9ollczttx giauarm bjljcob t
e4osfz dsmbcy4qp06 4dp4na xxxoiqrhq
jsqo6mmn 1c5aimoap4 tzpkl n
ngw8anmnyfz u mbvxdytm o
qw r6kuzvvguq kynmms mxmalwytw w5mjh n6fhkkcy44 m8eu
s e ntdonumc q7re tzy3u
s4yfv9zl m imu t eggmez na3x5 ms1tqu262sy
t0qc nndvlmr ydcfkpw jzdccrt mf0zh tz avslf1w w rc8wo
tdnmxr8x ago fkwbre wov8s spwbp6jen uxfanui7zf fmlqpvndmzc sz wnn
umybw8skgsa x vit5wwe 1memq4j5 iwoaivaru owvtsb5m bj gt ybhodotfexb
v67nlfkz5y krb81cl2qd5 ljdw ripkgtx cndk8aw d1
vrqjms5k ml 7
x zjcjzrta c5b5guqt 2lvx s 4 lz9k0 caz2q47 eccx
y8y tr5onzrj59 i473rhay qawm0zz nf0h0y
yszlkiv 2h5 3 gy
z q im9it1xz

13:00,584$ for x in *; do
firstletter=`echo "$x" | sed -e 's/^\(.\).*$r [a-z] [A-Z]`;
rest=`echo "$x" | sed -e 's/^.\(.*$\)/\1/'`;
if test "$x" != "$firstletter$rest"; then
mv "$x" "$firstletter$rest";
fi;
done

13:00,585$ ls
0hkf1te i7gxo15xvk ej6m4zmqz nbt jhjbvrdny qsiavdube 6jb9ej m0m4ktxnsi
2t1 5ugh z 0eip 85fwvxlebl2 ummokk r keoh7oy 8owjvqck3
4pq88o ombkr2zc duoeq3 irn4lpy ghj0qu c5yuos
6ej7gk v vn7fe5ae y 0hp9memhlk8 rucarvdj osfyx 9
7fsubxehovk uwdn9r sc u yvkrkwp kkqzyh rshquitc 1phhx2c
9yadyp hbz lu9 phvciwjigob x3y6d
B9ampeatph apzce mul1n 88d2cyj 6zsadjjwz zz6ydll 4zr1fckvceg uftxhh
m5xacr8b
Dbadgaoij yvvac mb0 vjidb0 dsclv 9ollczttx giauarm bjljcob t
E4osfz dsmbcy4qp06 4dp4na xxxoiqrhq
Jsqo6mmn 1c5aimoap4 tzpkl n
Ngw8anmnyfz u mbvxdytm o
Qw r6kuzvvguq kynmms mxmalwytw w5mjh n6fhkkcy44 m8eu
S e ntdonumc q7re tzy3u
S4yfv9zl m imu t eggmez na3x5 ms1tqu262sy
T0qc nndvlmr ydcfkpw jzdccrt mf0zh tz avslf1w w rc8wo
Tdnmxr8x ago fkwbre wov8s spwbp6jen uxfanui7zf fmlqpvndmzc sz wnn
Umybw8skgsa x vit5wwe 1memq4j5 iwoaivaru owvtsb5m bj gt ybhodotfexb
V67nlfkz5y krb81cl2qd5 ljdw ripkgtx cndk8aw d1
Vrqjms5k ml 7
X zjcjzrta c5b5guqt 2lvx s 4 lz9k0 caz2q47 eccx
Y8y tr5onzrj59 i473rhay qawm0zz nf0h0y
Yszlkiv 2h5 3 gy
Z q im9it1xz

It should work as long as your filenames don't contain anything too wild in
them.
.



Relevant Pages

  • Re: generating unique letter combinations
    ... > example, abc = abc, ab, ac, bc, a, b, c for any length string. ... Instead of counting numbers, you count letters ... If your character set has all of the letters contiguous (like ...
    (comp.programming)
  • Re: combinations of letters
    ... Each combination should have all 26 letters of the alphabet in either ... uppercase or lowercase form. ... ABC, AbC, ABc, aBC, abc, etc. ...
    (microsoft.public.excel)
  • Re: combinations of letters
    ... Each combination should have all 26 letters of the alphabet in either ... uppercase or lowercase form. ... ABC, AbC, ABc, aBC, abc, etc.- Hide quoted text - ... AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ...
    (microsoft.public.excel)
  • Re: combinations of letters
    ... Microsoft MVP - Excel ... |>>uppercase/lowercase letters. ... | ABC, AbC, ABc, aBC, abc, etc. ...
    (microsoft.public.excel)
  • Re: Simple recursion problem. Need help.
    ... Anakin wrote: ... > that I want all combinations of the first three letters of the alphabet ... then I need to generate ABC, AB, AC, BC, A, B, C. ... Don't forget the empty case where there are no letters to print -- you can't ...
    (comp.lang.java.programmer)

Loading