Solved

Sed question

Posted on 2011-03-21
6
371 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now