change a specific characters to capital in a specific text
for example
else { for fileDOC in $location/*.doc do echo $fileDOC | tr [a-z] [A-Z] > $fileDOC cp $fileDOC ./DOC done } fi the fileDOC return e.g testDir/test1Dir/test2Dir//doc1.doc testDir/test1Dir/test2Dir//doc2.doc testDir/test1Dir/test2Dir//doc3.doc testDir/test1Dir/test2Dir//doc5.doc what i want is to change doc1 and doc2 and doc3 to capital (the name of the file) and return it to the variable fileDOC |
SO I have a few issues:
1. Please use [code][/code] tags around your code Quote:
b. This will now clobber anything previously inside the file. Is this what you wanted? Quote:
|
the program is to get files (in any directory specified by the path) that end with extension .doc and change the name of these files to capital (just the name ).
|
So as you are on Ubuntu you could just use:
Code:
rename -n 's/\([[:alpha:]]+\)\(\..*\)$/\U\1\2/' $location/*.doc |
mm ok just help with this if u can
Code:
capital=$( echo $fileDOC | tr '[a-z].doc' '[A-Z].doc' ) i want to change it to DOC1.doc how i can do it using the code above (using tr ) |
My understanding of tr is that it is a character by character translation and has no smarts about regex, hence your example will never work.
Is there a reason we cannot use another tool? |
ok give me another one but nt simple way to do it
|
Quote:
|
aha mm i can do it in a loop using the script but i want something smarter !
|
mm sorry i meant to say give another one but IN simple way
|
Well I would have to say the rename option is probably the most simple way. Other than that I think you would have to use a loop.
Something like: Code:
for FILE in $location/* |
thanks grail for the solution ...i found another solution using basename command
e.g: filename.doc [cod] basename filename.doc .doc | tr [a-z] [A-Z] [\code] will return FILENAME then i can combine it to .doc to get FILENAME.doc ;) ofcourse i may use a loop to get all the file in a directory that end with .doc and change it |
Nice ... I had not used the suffix option previously ... nice.
|
All times are GMT -5. The time now is 05:19 PM. |