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 Tue 21 Oct 2014, 14:58
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 Posts_count  
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]'
Sub_title: 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_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_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_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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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