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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [[HelloInCapitals]] to [[Hello In Capitals]]
# 1  
Old 10-08-2009
[[HelloInCapitals]] to [[Hello In Capitals]]

Hello community,

I got it all done except for one thing,


[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]

So now I want to split those in to


[[Hello In Capitals]]

or

[[Pharmaceutical Society Of Great Britain V Boots 1952]]

I am not so good at all this and get stuck with

Code:
sed -e 's/[A-Z]/ &/g' -e 's/[0-9].../ &/g' -e 's/^ //g' infile

But it changes EVERYTHING, and I only want to change Mediawiki links which
are in between [[ ]]

Last edited by Neo; 10-08-2009 at 08:55 AM.. Reason: Please use code tags. Thanks!
# 2  
Old 10-08-2009
try

Code:
sed 's/[^A-Z]*/& /g'

# 3  
Old 10-08-2009
something to start with:
Code:
echo '[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | nawk -F'(\\[\\[)|(\\]\\])' '{for(i=2;i<=NF;i+=2) {gsub("[A-Z]", " &", $i);$i="[["substr($i,2)"]]"};print}' OFS=


Last edited by vgersh99; 10-08-2009 at 09:35 AM.. Reason: missed OFS
# 4  
Old 10-08-2009
Code:
while read line; do
 outline=""
 for i in $line; do
   case $i in
     "[["*) i=$(echo $i |sed 's/\([a-z]\)\([A-Z0-9]\)/\1 \2/g') ;;
   esac
   outline="$outline $i"
 done
 echo ${outline# }
done<infile

# 5  
Old 10-08-2009
Smilie
Just a little improvement to avoid iuseless spaces before and after [[ ]]
Code:
echo '[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | 
nawk -F'(\\[\\[)|(\\]\\])' '{for(i=2;i<=NF;i+=2) {gsub("[A-Z]", " &", $i);$i="[["substr($i,2)"]]"};print}' OFS=""

Jean-Pierre.
# 6  
Old 10-08-2009
Another one with sed:

Code:
echo '[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | 
sed 's/[A-Z]/ &/g; s/\[ /\[/g'

# 7  
Old 10-08-2009
Wrench

Quote:
Originally Posted by aigles
Smilie
Just a little improvement to avoid iuseless spaces before and after [[ ]]
Code:
echo '[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | 
nawk -F'(\\[\\[)|(\\]\\])' '{for(i=2;i<=NF;i+=2) {gsub("[A-Z]", " &", $i);$i="[["substr($i,2)"]]"};print}' OFS=""

Jean-Pierre.
yep, caught that one as well.
also taking care of 'numbers':
Code:
echo '[[HelloInCapitals]] OrAnd [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | nawk -F'(\\[\\[)|(\\]\\])' '{for(i=2;i<=NF;i+=2) {gsub("[A-Z]|[0-9][0-9]*", " &", $i);$i="[["substr($i,2)"]]"};print}' OFS=



---------- Post updated at 08:53 AM ---------- Previous update was at 08:42 AM ----------

Quote:
Originally Posted by Franklin52
Another one with sed:

Code:
echo '[[HelloInCapitals]] or [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | 
sed 's/[A-Z]/ &/g; s/\[ /\[/g'

Code:
echo '[[HelloInCapitals]] OrAnd [[PharmaceuticalSocietyOfGreatBritainVBoots1952]]' | sed 's/[A-Z]/ &/g; s/\[ /\[/g'
[[Hello In Capitals]]  Or And [[Pharmaceutical Society Of Great Britain V Boots1952]]

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