Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 24 Oct 2014, 09:12
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to translate tr '[a-z]' '[ a- z]'
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Wed 11 Aug 2010, 11:18    Post subject:  How to translate tr '[a-z]' '[ a- z]'
Subject description: I want to add space between letters
 

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 ?
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Mon 15 Nov 2010, 17:21    Post subject:  

# 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
Back to top
View user's profile Send private message Visit poster's website 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Tue 16 Nov 2010, 10:51    Post subject:  

Karl Godt

I found this snip http://www.unix.com/shell-programming-scripting/45705-add-spaces-between-characters.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:

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


Joe

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Tue 16 Nov 2010, 11:58    Post subject:  

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:
#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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 17 Nov 2010, 13:30    Post subject:  

get string length

here's an easy one to read

Code:

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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Fri 19 Nov 2010, 02:23    Post subject:  

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
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Tue 23 Nov 2010, 12:31    Post subject:  

/usr/local/jwmconfig2/confirmKey

sed -e "s#ALT#1#i" $TMP1 > $TMP2
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0605s ][ Queries: 11 (0.0152s) ][ GZIP on ]