[[HelloInCapitals]] to [[Hello In Capitals]]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [[HelloInCapitals]] to [[Hello In Capitals]]
# 8  
Old 10-08-2009
Code:
perl -pe's/\B(?:[[:upper:]]|\d+)/ $&/g'

# 9  
Old 10-08-2009
Quote:
Originally Posted by radoulov
Code:
perl -pe's/\B(?:[[:upper:]]|\d+)/ $&/g'

Code:
$ echo '[[HelloInCapitals]] OrAnd [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | perl -pe's/\B(?:[[:upper:]]|\d+)\B/ $&/g'
[[Hello In Capitals]] Or And [[Pharmaceutical Society Of Great Britain VBoots 1952]]

# 10  
Old 10-08-2009
Noticed it, work in progress Smilie

---------- Post updated at 03:08 PM ---------- Previous update was at 03:06 PM ----------

Code:
perl -pe'
  s/\[\[(.*?)\]\]/($x=$1)=~s#\B([[:upper:]]|\d+)\B# $1#g;"[[".$x."]]"/eg
  '

# 11  
Old 10-08-2009
This should also take care for the numbers, if you want to process only words. For lines including words within double square brackets use one of those solutions above.

Code:
sed 's/[A-Z]/ &/g; s/[0-9][0-9]*/ &/g; s/\[ /\[/g'

# 12  
Old 10-08-2009
Slightly modified:

Code:
zsh-4.3.10[t]% print '[[HelloInCapitals]] AndOr [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' |
perl -pe'
  s/\Q[[\E(.*?)\Q]]\E/($x=$1)=~s#\B([[:upper:]]|\d+)\B# $1#g;"[[".$x."]]"/eg
  '
[[Hello In Capitals]] AndOr [[Pharmaceutical Society Of Great Britain V Boots 1952]]



---------- Post updated at 03:17 PM ---------- Previous update was at 03:15 PM ----------

Quote:
Originally Posted by Franklin52
This should also take care for the numbers, if you want to process only words. For lines including words within double square brackets use one of those solutions above.

Code:
sed 's/[A-Z]/ &/g; s/[0-9][0-9]*/ &/g; s/\[ /\[/g'

This one substitutes outside of the [[ ]] as well.

Last edited by radoulov; 10-08-2009 at 10:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Directory find in small and capitals

I've a very trivial thing bothering me. I'm rather new in scripting so I'll keep asking stupid questions. Here is small script that does backup of mails. --- for i in `cat /maildir.dir` do echo $i maildir=`echo $i|sed 's@^./usr/@@'` for j in $i/* do && { st="`find $j/backup -name "*"... (3 Replies)
Discussion started by: nitin
3 Replies
Login or Register to Ask a Question