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

I want to delete only some spaces(say 4) after the line$#*425 with space

I am not able to complete it please suggest

echo "line$#*425 with space          " | sed 's/ /\1 \2/g'

i am thinking of using od -b also but still not able to figure it out

how do i do it

NOTE:spaces could be a normal " " or a tab character also

EDIT:heres how i did a test to check for the below answer

[root@testgfs2 test]$echo -e "line$#*425 with space \t     "  | sed 's/[[:blank:]]\{4\}$//' | od -b
0000000 154 151 156 145 060 052 064 062 065 040 167 151 164 150 040 163
0000020 160 141 143 145 040 011 040 012

the deletion is happening not after the space word but at the end of line. the tab character(011) is still there

share|improve this question
up vote 2 down vote accepted

Your code sample doesn't seem to match your question. Your code sample has no groupings, so \1 and \2 don't reference anything. Here's what it sounds like you're asking for:

sed 's/space[[:blank:]]\{4\}/space/' <<< "line$#*425 with space          "
share|improve this answer
i guess,but this will delete charters at the end of the line i want the deletion to happen after the word space – munish Feb 20 '13 at 13:17
@munish - See my updated answer. – Chris Down Feb 21 '13 at 2:27

Put the part(s) you want to keep in a group. Don't forget to quote the characters that need quoting in the regex (\[.*^$).

sed -e 's/\(line\$#\*425 with space\)[ \t][ \t][ \t][ \t]/\1/'

If your sed doesn't support \t to mean a tab character, replace \t by a literal tab character.

share|improve this answer

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.