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

please advice how to delete the spaces between "=" to the value/string ( after the "=" character) , should be implemented by awk or sed or perl command and command must to fit for solaris OS , ( command should be in my bash script )

I have SOLARIS 10 OS

example 1 ( before update )

more file

 b= 45
 c=   4
 d= 98
 f= gdtd
 g=     @7h
 parameter5=    87

example 2 ( after update )

more file

share|improve this question

migrated from serverfault.com Aug 29 '12 at 13:00

This question came from our site for system and network administrators.

Which version of Solaris ? – Iain Aug 29 '12 at 6:31
up vote 6 down vote accepted

Try this:

sed 's/=[ \t]*/=/' input.txt

Specify an -i option for in-place edit if you want.

sed -i not fit for solaris

Either redirect to another file and rename to original or using perl instead:

perl -pi -e 's/=[ \t]*/=/g' input.txt
share|improve this answer
sed -i not fit for solaris – yael Aug 29 '12 at 6:31
updated my answer. – quanta Aug 29 '12 at 6:39
Even with GNU sed, that can be a problem (when POSIXLY_CORRECT is set) as [ \t] is meant (as per POSIX) to match space backslash or t. You want [[:blank:]] instead which is POSIX. – Stéphane Chazelas Aug 29 '12 at 13:31
For the perl version, use s/=\s*/=/g. and if there's any chance there might be whitespace before the = as well as after it, use: s/\s*=\s*/=/g. and the /g modifier is only necessary if there's a chance there might be more than one = symbol needing whitespace stripping per line. – cas Aug 30 '12 at 2:53
sed 's/=[[:blank:]]*/=/' < file.in > file.out
share|improve this answer
On Solaris this doesn't work with /usr/bin/sed but it does work with /usr/xpg4/bin/sed. – Iain Aug 29 '12 at 6:59

Plenty of ways to do this, but the simplest and crudest - take the file and pipe it through sed: cat $filename | sed -e 's/ //g'

share|improve this answer
not sure if it work because if I have 20 space or TAB , – yael Aug 29 '12 at 6:27
@yael if you meant whitespace you should ave said so, as it is you say spaces so this answer will work although it may not do what you want if there are spaces before the = sign. You should read the sed man page in particular the about the g qualifier. – Iain Aug 29 '12 at 6:36
cat isn't required sed will take a filename itself - sed -e 's/ //g' $filename works – Iain Aug 29 '12 at 6:37

For solaris 11, the way to turn multiple spaces into a single space inline is:

[commmand_with_output] | sed -e 's/ */ /g'

two spaces with an asterisks

share|improve this answer
This isn't exactly what the question asked though — it aks about space around equal signs. And this isn't the only way, [:blank:] mentioned in other answers is ok too. – Gilles Jun 20 '14 at 23:30

Your Answer


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