473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Complexed serach and replace task, advice?

I have search and replace task and was hoping to get some advice. I
have a large text file of remote access users from Cisco's ACS
dumpfile that I need to batch alter 2000 of 3000 users. And example
user record (they are not all the same size)

#-----------------------------------------------------------------------------
Name : myuser
State : 0
S_flags : 0
Aging policy : group1
Good count : 0
Warning count : 0
Change count : 0
Last change Lo: 1648245808
Last change Hi: 29591352
Last auth Lo : 0
Last auth Hi : 0
Rights : 1
Type : 256
EnableType : 4
Status : 4
Reset : 1
Expiry : 302 103 0 4294963983 0 5
MaxSession : 65535
MaxSess2 : 0
Profile : 1
LogonHrs : 0x0016 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff
Alias : 0
Value Flags : 524336
CounterVals_00: 0 0 0 0
CounterRst_00 : 0 0
CounterVals_01: 0 0 0 0
CounterRst_01 : 0 0
##--- User End

I have a simple text file of all the usernames that must be acted on
already, and i was hoping to find a scripted method of searching this
file to locate my usernames, then change the TYPE and STATUS lines for
each respective user to alternate values.

My problem is how to do a search that will stop at a username, reach
forward in the file to find the next occurance of TYPE and then
STATUS, make the replacements, and then continue searching the file
for the rest of the usernames.

Doing a bulk replace of all status and type, that's easy with "sed',
and if i could get Grep to go through a file, lock on a name match,
and start sed off from that point I might be ok, but I don't see how
that could be done. So I am betting Perl is my best and perhaps only
option to do this with minimal developement time. Any text
manipulators out there see a way to do this from what I have
described?

Nick
ne*****@or.blm.gov
Jul 19 '05 #1
1 2035
gr***@nickellson.com (Nick Ellson) wrote in message news:<a0**************************@posting.google. com>...
I have search and replace task and was hoping to get some advice. I
have a large text file of remote access users from Cisco's ACS
dumpfile that I need to batch alter 2000 of 3000 users. And example
user record (they are not all the same size)

#-----------------------------------------------------------------------------
Name : myuser
State : 0
S_flags : 0
Aging policy : group1
Good count : 0
Warning count : 0
Change count : 0
Last change Lo: 1648245808
Last change Hi: 29591352
Last auth Lo : 0
Last auth Hi : 0
Rights : 1
Type : 256
EnableType : 4
Status : 4
Reset : 1
Expiry : 302 103 0 4294963983 0 5
MaxSession : 65535
MaxSess2 : 0
Profile : 1
LogonHrs : 0x0016 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff
Alias : 0
Value Flags : 524336
CounterVals_00: 0 0 0 0
CounterRst_00 : 0 0
CounterVals_01: 0 0 0 0
CounterRst_01 : 0 0
##--- User End

I have a simple text file of all the usernames that must be acted on
already, and i was hoping to find a scripted method of searching this
file to locate my usernames, then change the TYPE and STATUS lines for
each respective user to alternate values.

My problem is how to do a search that will stop at a username, reach
forward in the file to find the next occurance of TYPE and then
STATUS, make the replacements, and then continue searching the file
for the rest of the usernames.


You don't. Perl is a procedural programing lanuage with variables
that can change. You simply process the whole file line-wise and note
user name as it goes past.

The following is not very efficient but it works:

#!/usr/bin/perl
use strict;
use warnings;

my %alternate_values =
(
myuser => { Type => 'Mad', Status => 'Hungry' },
);

my $alt = {};
while(<>) {
$alt = $alternate_values{$1} || {} if /^Name\s+:\s+(\S+)/;
for my $field ( keys %$alt ) {
s/^($field\s+:\s+)(\S+)/$1$alt->{$field}/g;
}
print;
}

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
7
by: Shane Story | last post by:
Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for example) my prog with command line args, as a job to be run. Would like to make it easier on the user to run the app. ...
11
by: Max | last post by:
I'm writing a program that needs to be able to create custom .job files and add them to the scheduled tasks folder. What I'd like to know is, what is the format of a .job file and how do I go about...
4
by: tungchau81 | last post by:
Hi, I have a lot of JSP files that serve as pure JavaScript code. I need to convert all JavaScript comments inside these JSP files to JSP comments which use <%-- // --%> tags. Instead of doing it...
8
by: JDT | last post by:
Hi, The last statement at the end of this post is to delete a set member 7.7. I set a break point inside ltstr::operator(). I found out that STL binary-seach the set twice. How come? I have...
3
by: lai_waiman | last post by:
Dear All, I have problems on doing some long lasting job in a web services. Let me first provide some background information first. I have a ASP.NET web page, which will call another Web...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
1
by: Curious | last post by:
I'm working on a word replacement program in .NET. I have a list of words spelt in American English and need to replace them with translated British spelling while keeping the upper or lower cases...
2
by: raknin | last post by:
Hi, Is there any way using mysql to serach a values in a string where I don't care what is in between, for example: I have a row which contains the following string in the foloowing format ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.