Bash text editing problem
From: Foptop (youknow_at_idont.com)
Date: 03/04/04
- Next message: John Mazza: "Re: Wiping a hard drive in linux"
- Previous message: Dave: "Stellar Phoenix for Linux"
- Next in thread: Jacob Westenbach: "Re: Bash text editing problem"
- Reply: Jacob Westenbach: "Re: Bash text editing problem"
- Reply: Daniel Ganek: "Re: Bash text editing problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 04 Mar 2004 19:05:34 GMT
don't know if anyone remembers, but i asked the newsgroup of a way to
convert the first letter of each word in a filename to uppercase. the
conditions were: it had to be bash ( haven't learnt any other shell
languages yet ) ; words were separated with an underscore ; cases of
letters could be anything. a solution was quickly posted. i think the
guy's name was Dan, could be wrong but i think that's it. here is his
function:
#!/bin/bash
#
function upperCase
{
filename=$(IFS=_
set -- $1
for i
do
remain=${i#?}
firstChar=${i%${remain}}
upper=$(echo $firstChar|tr [:lower:] [:upper:])
echo -e "${upper}${remain}_\c"
done
)
echo ${filename%_}
}
upperCase $1
i'm just posting this again since it works perfectly and the coding is
nice and neat - someone might want it as i could not find a proper
solution to this. i saw a solution in perl, but didn't understand it, so
couldn't adapt it. it only goes one way though - if everything is in
uppercase, it won't change the other characters to lowercase. it works
when everything is lowercase or if the only capitals are in the first
letter of some/all of the words. this can all be changed easily though,
but the problem i couldn't figure out was how to split up a word and deal
with the first character and the rest of the word separately. so far, i've
made a few scripts based on this function to automate a lot of tasks.
thanks again to Dan.
- Next message: John Mazza: "Re: Wiping a hard drive in linux"
- Previous message: Dave: "Stellar Phoenix for Linux"
- Next in thread: Jacob Westenbach: "Re: Bash text editing problem"
- Reply: Jacob Westenbach: "Re: Bash text editing problem"
- Reply: Daniel Ganek: "Re: Bash text editing problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|