Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   sed regexp mystery (http://www.velocityreviews.com/forums/t24136-sed-regexp-mystery.html)

John K. Humkey 07-08-2003 03:55 AM

sed regexp mystery
 
Ok, it's sed not perl, but it's primarily a regexp question that I've
encountered (and failed to understand) before. . .

#
# When trying to convert a variable number
# of spaces separating fields, to fields
# separated by single commas, if your "input"
# file looks like the following lines. . .
#
#alpha bravo charlie delta echo fox
#alpha bravo charlie delta echo fox
#alpha bravo charlie delta echo fox
#
# and your're trying to convert it to the following. . .
#
#alpha,bravo,charlie,delta,echo,fox
#alpha,bravo,charlie,delta,echo,fox
#alpha,bravo,charlie,delta,echo,fox
#
# Why don't any of the next 5 lines work?
cat input | sed -e "s/ +/,/g"
cat input | sed -e "s/ */,/g"
cat input | sed -e "s/ {1,10}/,/g"
cat input | sed -e "s/[ ]*/,/g"
cat input | sed -e "s/[ ]+/,/g"
#
# Because the above 5 lines all look like
# valid methods of substituting one comma
# for one or more spaces.
#
# And yet, the next line DOES work.
cat input | sed -e "s/[ ] */,/g"
#

I've also tried the g/before/s//after/g type lines with even less success.

Thoughts?

jkh


All times are GMT. The time now is 06:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.