Solved

Sed question

Posted on 2011-03-21
6
374 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
Technology Partners: 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 500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
sudo logging 5 109
Linux : can't create transaction lock error 1 84
Most secure Linux or x86 Unix that are least prone to ransomware/malware 24 141
Martian Packets Unix 5 72
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

740 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