How to translate tr '[a-z]' '[ a- z]'

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

How to translate tr '[a-z]' '[ a- z]'

#1 Post by Karl Godt »

I think the headline could be self explaining ....

Another thing would be the print or selection of single items of a string :

for example
if I have STR="aBcDEFghIjK?!()} { |\/>.,; " ' 123"

Until now I can only ' elofSTR="`expr length $STR`" '

What is the right syntax for these two questions ?

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

# echo $STR | sed -r 's/(.)/ \1/g'
A B C D
# echo $STR | sed -r 's|(.)| \1|g'
A B C D
# echo $STR | sed -r 's_(.)_ \1_g'
A B C D
# echo $STR | sed -r 's:(.): \1:g'
A B C D

# echo $STR | sed -r 's:(.): \0:g'
A B C D
# echo $STR | sed -r 's:.: \0:g'
A B C D

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#3 Post by big_bass »

Karl Godt

I found this snip http://www.unix.com/shell-programming-s ... cters.html

you have spaces to start with in your string so enclose the original string with single quotes first then



echo "$STR" | sed 's/./ &/g;s/^ //'


Code: Select all

STR='what  #%$][ % {}  you want  to say :D '
echo "$STR" | sed 's/./ &/g;s/^ //' 
Joe

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#4 Post by technosaurus »

damn just the other day I did this by accident when I was trying to do something else with sed - can't remember, but it was really short and contained *

you can get the length of a string with

${#VAR}

here is an example usage:

Code: Select all

#keeps adding the "9" character to the end of the string NEWVER
# until it is the same length as the string VER
while [ "${#NEWVER}" -lt "${#VER}" ]
do
NEWVER=${NEWVER}9
done
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#5 Post by big_bass »

get string length

here's an easy one to read

Code: Select all

any_variable="some big string goes here"
echo ${#any_variable}
the output is 25

the bold part is the format to use
${#any_variable}

Joe

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#6 Post by Karl Godt »

seems I found another partial cut character for `sed` : '!'

/usr/local/jwmconfig2/focusModel :

SEDFOCUS=s!Model\>${VALUE}!Model\>${CHOICE}!g

sed -e "$SEDFOCUS" $CONFIG > $CONF

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#7 Post by Karl Godt »

/usr/local/jwmconfig2/confirmKey

sed -e "s#ALT#1#i" $TMP1 > $TMP2

Post Reply