Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sed question

Posted on 2011-03-21
6
Medium Priority
?
382 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:gchen91789
  • 4
  • 2
6 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35187624
sed 's/\(BuildNumber=.*\)/\1 server1/' propertyfile

wmp
0
 

Author Comment

by:gchen91789
ID: 35193897
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
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35194055
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?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:gchen91789
ID: 35194184
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

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35194323
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
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 35197096
If you don't insist in sed we can of course always use awk:

awk '{if ($0~"BuildNumber=") print $0, "wax1"; else print $0}' TP.properties

If "BuildNumber" is required to start at position 1 use this:

awk '{if ($0~"^BuildNumber=") print $0, "wax1"; else print $0}' TP.properties

wmp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question