- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: PERL help needed by newbie
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 05:16 AM
тАО05-17-2005 05:16 AM
PERL help needed by newbie
Here is my problem:
I have few files on each of my servers with around a thousand lines in each, from which I need to make a simple search and replace. File format is simple:
ParameterName Value
where both ParameterName and Value are alphanumeric strings, e.g.,
FilesystemThreshold 92%
LargefileValue 9999999
what I need to do is to search for the ParameterName and replace the value to a preset string on the same line, but this line may repeat itself multiple times (repetition count varies from one file to the other) in this file and I have to do the replacement on every each occurance of the ParameterName.
What would be a simple one or two liner perl command to accomplish this ?
Thank you for your help.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 05:20 AM
тАО05-17-2005 05:20 AM
Re: PERL help needed by newbie
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=830280
This one is also useful.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=780662
Its not breaking down to ask a question. Its efficient use of your time.
Please do not hesitate to ask again.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 06:16 AM
тАО05-17-2005 06:16 AM
Re: PERL help needed by newbie
Why not just use "sed" ??
Here are two ways with sed:
(1) On the command line:
sed -e "s/\(ParameterName1\) \(.*\)/\1 MyAnswer/g" -e "s/\(ParameterName3\) \(.*\)/\1 YourAnswer/g" -e "s/\(ParameterName5\) \(.*\)/\1 TheAnswer/g" ./testparams > NEWFILENAME
(2) Create a file with the parameters that need changing:
vi testvalues
Add lines like this:
s/\(ParameterName1\) \(.*\)/\1 MyAnswer/g
s/\(ParameterName3\) \(.*\)/\1 YourAnswer/g
s/\(ParameterName5\) \(.*\)/\1 TheAnswer/g
sed -f testvalues ./testparams > NEWFILENAME
Here it is in action (without the redirect output to a new file):
[root@rndspt01 /tmp]# cat testparams
ParameterName1 hello
ParameterName1 test
ParameterName2 mom
ParameterName3 there
ParameterName4 why
ParameterName5 This is strange
ParameterName3 where
[root@rndspt01 /tmp]# sed -e "s/\(ParameterName1\) \(.*\)/\1 MyAnswer/g" -e "s/\(ParameterName3\) \(.*\)/\1 YourAnswer/g" -e "s/\(ParameterName5\) \(.*\)/\1 TheAnswer/g" ./testparams
ParameterName1 MyAnswer
ParameterName1 MyAnswer
ParameterName2 mom
ParameterName3 YourAnswer
ParameterName4 why
ParameterName5 TheAnswer
ParameterName3 YourAnswer
OR with the use of a parameter file:
[root@rndspt01 /tmp]# cat testvalues
s/\(ParameterName1\) \(.*\)/\1 MyAnswer/g
s/\(ParameterName3\) \(.*\)/\1 YourAnswer/g
s/\(ParameterName5\) \(.*\)/\1 TheAnswer/g
[root@rndspt01 /tmp]# sed -f ./testvalues ./testparams
ParameterName1 MyAnswer
ParameterName1 MyAnswer
ParameterName2 mom
ParameterName3 YourAnswer
ParameterName4 why
ParameterName5 TheAnswer
ParameterName3 YourAnswer
[root@rndspt01 /tmp]#
live free or die
harry d brown jr
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 08:54 AM
тАО05-17-2005 08:54 AM
Re: PERL help needed by newbie
perl -pe 'BEGIN{$p=shift ; $v=shift ;}{s/ .*/ $v/ if /^$p /o}' ParameterName Value file1 file2 ... filen
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 09:21 AM
тАО05-17-2005 09:21 AM
Re: PERL help needed by newbie
perl -pi -e 'BEGIN{$p=shift ; $v=shift ;}{s/ .*/ $v/ if /^$p /o}' ParameterName Value file1 file2 ... filen
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2005 11:39 AM
тАО12-28-2005 11:39 AM