Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > sed regexp mystery

Reply
Thread Tools

sed regexp mystery

 
 
John K. Humkey
Guest
Posts: n/a
 
      07-08-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
mystery regexp Steve Throckmorton Ruby 4 07-17-2006 05:47 PM
add blank lines after word MAC (sed/awk or perl??) NNTP Perl 2 04-07-2004 06:04 AM
using perl on the command line, like sed or awk gorda Perl 2 10-21-2003 06:38 AM
sed awk or perl for this? NNTP Perl 13 09-30-2003 06:49 AM



Advertisments