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

  • Which version of Solaris ? – user591 Aug 29 '12 at 6:31

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
  • 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
  • 2
    On Solaris this doesn't work with /usr/bin/sed but it does work with /usr/xpg4/bin/sed. – user591 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'

  • 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. – user591 Aug 29 '12 at 6:36
  • 3
    cat isn't required sed will take a filename itself - sed -e 's/ //g' $filename works – user591 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

  • 1
    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 'SO- stop being evil' Jun 20 '14 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy