Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sed question

Posted on 2011-03-21
6
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

721 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