Link to home
Start Free TrialLog in
Avatar of gchen91789
gchen91789

asked on

Sed question

I have a property file, i need add server name at end of the line start with "BuildNumber".

For example:
From:
BuildNumber=1.1.4
To:
BuildNumber=1.1.4 server1

Please provide answer by using SED command.

Thanks,

Gary
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

sed 's/\(BuildNumber=.*\)/\1 server1/' propertyfile

wmp
Avatar of gchen91789
gchen91789

ASKER

wmp,

I have tried the solution you provide, but it will overwrite in the beginning of the line, not at end of the line.

Thanks,

Gary
It works for me, with AIX sed as well as with GNU sed, under ksh as well as under bash.

What is your OS?

Did you use the command exactly as I posted it?

Please note particularly the single quotes around the whole command, the escaped parentheses around the search string \(   \), and "\1" following the second /.

.* following the = sign is also very important!

sed 's/\(BuildNumber=.*\)/\1 server1/' propertyfile


Does your inputfile look exactly as you posted it?

OK. Here is the entry before excute the sed command:
BuildNumber=Release 12.3.1.409.10
list below was the command I use.
sed 's/\(BuildNumber=.*\)/\1 wax1/' TP.properties
The result:
 wax1Number=Release 12.3.1.409.10

I am using UNIX SunOS.
Thanks for your help.

Gary

Well,

I don't have a SunOS box at hand.

This is what I get, using what you posted in your last comment:

BuildNumber=Release 12.3.1.409.10 wax1

No idea why it doesn't work for you.

Do you have GNU sed installed, by any chance? Look for /opt/sfw/bin/gsed!

If no luck I think you should delete this Q and post it again in the SunOS zone.

wmp
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial