user490735
user490735

Reputation: 765

How to replace whitespace with one blank using sed?

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

Upvotes: 4

Views: 9788

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 359855

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.

Upvotes: 7

Related Questions