Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

why n option is not working here

   [root@testgfs2 final]# echo a b c | sed -ne 's/[[:blank:]]/"/gp' -ne 's/^/"/pg' -ne 's/$/"/pg'

i just need :


actually i want sed to do somehting like :

echo a b c d | sed ...


'a' 'b' 'c' 'd'
share|improve this question
up vote 3 down vote accepted

The problem is you are using p as a modifier which prints the "pattern space", i.e. result. To fix your example just do:

echo a b c | sed -e 's/[[:blank:]]/"/g' -e 's/^/"/g' -e 's/$/"/g

You may also consider using something like:

echo a b c | sed -e 's/\(\w*\)/"\1"/g'


share|improve this answer
+1. Or the shorter ERE version: sed -r "s/\w+/'&'/g". – Thor Feb 27 '13 at 10:31
what does \w* stands for or does – munish Feb 27 '13 at 10:32
@munish: \w is a GNU sed extension and is equivalent to this group [[:alnum:]_]. What version of sed are you using? – Thor Feb 27 '13 at 11:09
Which means sed "s/[^[:blank:]]\{1,\}/'&'/g" would be standard, more correct (as you want non-blanks, not just alnums) and more portable. – Stéphane Chazelas Feb 27 '13 at 21:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.