- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Update a word in a line
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
тАО06-16-2009 05:09 AM
тАО06-16-2009 05:09 AM
Update a word in a line
I'm trying to update a line in the backup file,but its not updating properly.
use File::Copy; @files=;
foreach $event (@files) {
my $backup=$event.".bak";
copy($event,$backup);
open(MYFILE,"<$backup")|| die "cant find it";;
while (
#print $_."\n";
if (/^not/) {
s/OCAL/OWN/e;
print $_."\n";
}
}
close(MYFILE);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 05:28 AM
тАО06-16-2009 05:28 AM
Re: Update a word in a line
"but its not updating properly."
so, is it erroring out? changing something you don't want it to? changing nothing?
do you suppose posting the contents (or a relevant portion thereof) of the original file might help? Along with a (detailed) description of the desired change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 05:45 AM
тАО06-16-2009 05:45 AM
Re: Update a word in a line
You are apparently trying to do updates while creating backup copies of files. There is an easier way.
First, your code doesn't update anything since you don't write to anything other than STDOUT. There are other errors too.
You could do this:
# cat ./myupdater
#!/usr/bin/perl
use strict;
use warnings;
{
local $^I = '.bak';
local @ARGV = ( );
while (<>) {
if (/^not/) {
s/LOCAL/OWN/g;
}
print;
}
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 05:46 AM
тАО06-16-2009 05:46 AM
Re: Update a word in a line
Sorry!!
File format like below:
file:dsjfsdkaf
header:iewrweur
not:updat,OCAL,3247283,wrwe
not:updat,OCCL,32424323,werwe
footer:werwer
The OCAL i want to change to OWN.
And the file is copied as it is ,the change is not done as required.
But this oneliner works :
perl -p -i.bak -e 'if (/^not/) { s/OCAL/OWN/; } ' *05
Thanks,
Priya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 05:48 AM
тАО06-16-2009 05:48 AM
Re: Update a word in a line
Two more comments. The code I offered above is the equivalent of a commandline edit and could be reduced to that too.
Second, please don't forget to evaluate the answers to your previous question(s):
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1347038
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 06:22 AM
тАО06-16-2009 06:22 AM
Re: Update a word in a line
Use fbackup instead of tar as fbackup have more features.
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=663262&admit=109447627+1245161973650+28353475
Regards,
Durvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 06:23 AM
тАО06-16-2009 06:23 AM
Re: Update a word in a line
Sorry...........
Durvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 06:49 AM
тАО06-16-2009 06:49 AM
Re: Update a word in a line
I tried the same code as given but its still not updating the file for OCAL to OWN.
The file is just copied.
Thanks,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 06:53 AM
тАО06-16-2009 06:53 AM
Re: Update a word in a line
> Still don't know why I can login to some non-root users via telnet, but not others.
Well, I thought you meant change LOCAL to OWN. My code was written to affect that change, so amend it the way you need it.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 07:08 AM
тАО06-16-2009 07:08 AM
Re: Update a word in a line
Can you tell me what was wrong in the first code?
And secondly the number of files will be huge,maybe like 3-4lakhs.So will @ARGV have any issue?
Priya