Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

 a=2
 b= 45
 c=   4
 d= 98
 e=09
 f= gdtd
 g=     @7h
 parameter5=    87

example 2 ( after update )

more file

a=2
b=45
c=4
d=98
e=09
f=gdtd
g=@7h
parameter5=87
share|improve this question

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

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

    
Which version of Solaris ? –  Iain Aug 29 '12 at 6:31
add comment

4 Answers 4

up vote 5 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
add comment
sed 's/=[[:blank:]]*/=/' < file.in > file.out
share|improve this answer
2  
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
add comment

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
1  
cat isn't required sed will take a filename itself - sed -e 's/ //g' $filename works –  Iain Aug 29 '12 at 6:37
add comment

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
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 Jun 20 at 23:30
add comment

Your Answer

 
discard

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