tags:

views:

31

answers:

1

Using sed "s/[[:blank:]]*/ /g" a>b doesn't seem to work.

+1  A: 

You need to change the asterisk to a plus sign:

sed "s/[[:blank:]]\+/ /g" a>b

or use an alternative that means the same thing:

sed "s/[[:blank:]][[:blank:]]*/ /g" a>b

or

sed "s/[[:blank:]]\{1,\}/ /g" a>b

Also, it's more helpful to post error messages or precise ways that behavior differs from expectations since "doesn't seem to work" conveys very little information.

Dennis Williamson
Thanks. I was a bit distracted and couldn't make sense of the fact that suddenly there were spaces where there were none before. :)
@user: Since `*` matches *zero* or more occurrences of a pattern, it can match the beginning and end of a string. Here's a simple example that turns three characters into five: `echo ' a '|sed 's/a*/x/g'`.
Dennis Williamson
The first time I tried it, if I remember correctly,sed "s/[[:blank:]]\+/ /g" a>b
[pessed enter for \n]worked fine, but now that I'm trying it again, it, the only line of the three versions you provided, doesn't seem to have any effect.
@user: I'm afraid I don't understand. What do you mean by "the only line of the three versions you provided"? What does an example of your input look like? Do any of my versions work?
Dennis Williamson
I'm saying the other 2 work fine. Example input:
a bv input aaa endinput
(Apparently this site compresses whitespace in comments). I just tried this on some files containing multiple tabs and spaces.
@user: What version of `sed`?
Dennis Williamson
4.2.1 from http://gnuwin32.sourceforge.net/packages/sed.htm
@user: I have gnuwin32 `sed` version 4.2 and all three `sed` commands work for me.
Dennis Williamson
I realized that I've been typing + instead of \+. Thanks for helping me.