Sponsored Content
Full Discussion: Capturing Particular Data
Top Forums Shell Programming and Scripting Capturing Particular Data Post 302299674 by muhmsida on Friday 20th of March 2009 06:43:15 PM
Old 03-20-2009
Error Capturing Particular Data

Hi everyone!

Can any one help me out regarding capturing relevant data from a file.

For e.g, if i want to capture the comment written after "Prompt:" for a particular date, like for this case what would be the command to capture the tag written after "Prompt:" for Date: 2009-03-20.

A brief intro is for your reference:

Actually i want to capture number of Prompt with their tags for one particular day using script, if any one can help me out in letting me know the command i can use that in my script later.

This script will run on daily basis and will capture the tags written after "Prompt:" for one particular date.


=============Date: 2009-03-18=============
[01:48:01][DS1] Prompt: Local network interface[172.17.215.10:13005] is opened.
[01:48:08][DS1] Prompt: Reading scu system config file successfully.
[01:48:08][DS1] Prompt: NrOfRCOMM 34-->35 of Item[RCOMM] in scusys.cfg changed.
[01:48:08][DS1] Prompt: Item[RCOMM] of scusys.cfg changed, Added as follow:
RCOMM_FE_ID[34] = 65
RCOMM_Version[34] = 1
RCOMM_OperationID[34] = 1120
RCOMM_UniqueOperationID[34] = 1120
RCOMM_ServiceKey[34] = 1001
RCOMM_ControlFlag[34] = 0
RCOMM_ExecuteFE[34] = 0
[01:48:08][DS1] Prompt: Refresh AS config file over, number of success: 2, number of failure: 0.
[01:48:08][DS1] Prompt: Local network interface[172.17.215.10:13000] is opened.
[01:48:08][DS1] Prompt: Detect a connection request from SAU(ip=172.17.215.152)
[01:48:08][DS1] Prompt: Detect a connection request from No.0 memory board.
[05:29:13][DS1] Prompt: Refresh AS config file over.
=============Date: 2009-03-19=============
[02:20:02][DS1] Prompt: Local network interface[172.17.215.10:13005] is opened.
[05:00:03][DS1] Prompt: Local network interface[172.17.215.10:13005] is opened.
=============Date: 2009-03-20=============
[02:20:02][DS1] Prompt: Local network interface[172.17.215.10:13005] is opened.
[05:00:04][DS1] Prompt: Local network interface[172.17.215.10:13005] is opened.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

capturing process id

I am newbie to unix shells world. I am trying to capture a background process id into a file so that it can be killed later. this process is basically a java program running in background as: java TestApp & this returning process id immediately. So how can i redirect that pid into a file.... (1 Reply)
Discussion started by: bvreddy
1 Replies

2. UNIX for Dummies Questions & Answers

Capturing some data from a file into a variable

I have a file with some values in a tab delimted format Eg: 'test' contains: a<tab>b<tab>c<tab>Trk_12345678 now i need to capture this value 'Trk_12345678' into a variable say 'x' and append that value of 12345678 to 12345679 and store is back to a new 'test1' file as : 'test1'... (11 Replies)
Discussion started by: shiroh_1982
11 Replies

3. Shell Programming and Scripting

Capturing Unix Traceroute data

Hi guys, I need a way to capture the host on the next-to-last hop in a traceroute output. The last output is the destination but I need to capture the router just before the last hop. I can do this in perl but I'm not so sure about Shell... I'm on AIX 5.3 using ksh any ideas? ... (3 Replies)
Discussion started by: TivoliGUY
3 Replies

4. Shell Programming and Scripting

Capturing Data between first quote and next quote

I have input file like RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12' I want to parse data which comed between first quote till next quote USER_WORK.TEST can you please suggest how to do that (4 Replies)
Discussion started by: scorp_rahul23
4 Replies

5. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

6. Shell Programming and Scripting

Capturing data between patterns

Hii, Friends, I want your help in one of my problem. My problem is as follows. I have a flat file as follows (Just a sample) MHT011 01(DOT)8750707asdfas8609 03(DOT)ASD3453ASD 09(DOT)876JHT87 11(DOT)sfd324ert TTT077 01(MOB)876786klj897 06(MOB)876JHT87 07(MOB)sfd324ert... (4 Replies)
Discussion started by: anushree.a
4 Replies

7. IP Networking

How to capturing packet data so i can see the Version, IHL, TOS, etc?

Helo Folks :) i had read an answer in this thread unixcom/programming/117551-calculate-ip-header-checksum-manually.html i need to know what the software name that was used to capturing packet data in a network, just like the packet's capture output that showed up in the thread. Thank you :)... (5 Replies)
Discussion started by: polutan
5 Replies

8. Red Hat

capturing data of nethogs

I have installed nethogs to see which process is sending load on the network. i would like to know how can i capture its data in a log file. Or is there is a unix command like script or tee which can help me to capture the data using cronjob (0 Replies)
Discussion started by: anshus1
0 Replies

9. Shell Programming and Scripting

capturing selective data from a vcd file

Hi, This is a vcd file.A vcd file may have 'n' modules. 1) I need to capture the data in bold,i.e. the module names (shown in bold) 2) Also i need to capture the data inside each individual module,say for tst_bench_top ,i need to capture data from line 4 to line 20 ... I just want one... (2 Replies)
Discussion started by: veerabahu
2 Replies

10. Shell Programming and Scripting

Perl : not capturing all the data from excel sheet

Hi folks, I am working on assignment that captures all the records(2 columns one column contains names and other contain date of birth) from excel sheet stored in a directory and checks for current date and month. If it matches current date and month then the matched records are printed as... (1 Reply)
Discussion started by: giridhar276
1 Replies
Net::CLI::Interact::Phrasebook(3pm)			User Contributed Perl Documentation		       Net::CLI::Interact::Phrasebook(3pm)

NAME
Net::CLI::Interact::Phrasebook - Load command phrasebooks from a Library VERSION
version 1.121640 DESCRIPTION
A command phrasebook is where you store the repeatable sequences of commands which can be sent to connected network devices. An example would be a command to show the configuration of a device: storing this in a phrasebook (sometimes known as a dictionary) saves time and effort. This module implements the loading and preparing of phrasebooks from an on-disk file-based hierarchical library, and makes them available to the application as smart objects for use in Net::CLI::Interact sessions. Entries in the phrasebook will be one of the following types: Prompt Named regular expressions that match the content of a single line of text in the output returned from a connected device. They are a demarcation between commands sent and responses returned. Macro Alternating sequences of command statements sent to the device, and regular expressions to match the response. There are different kinds of Macro, explained below. The named regular expressions used in Prompts and Macros are known as Match statements. The command statements in Macros which are sent to the device are known as Send statements. That is, Prompts and Macros are built from one or more Match and Send statements. Each Send or Match statement becomes an instance of the Net::CLI::Interact::Action class. These are built up into Prompts and Macros, which become instances of the Net::CLI::Interact::ActionSet class. USAGE
A phrasebook is a plain text file containing named Prompts or Macros. Each file exists in a directory hierarchy, such that files "deeper" in the hierarchy have their entries override the similarly named entries higher up. For example: /dir1/file1 /dir1/file2 /dir1/dir2/file3 Entries in "file3" sharing a name with any entries from "file1" or "file2" will take precedence. Those in "file2" will also override entries in "file1", because asciibetical sorting places the files in that order, and later definitions with the same name and type override earlier ones. When this module is loaded, a personality key is required. This locates a directory on disk, and then the files in that directory and all its ancestors in the hierarchy are loaded. The directory root is specified by two Library options. INTERFACE
new( \%options ) This takes the following options, and returns a loaded phrasebook object: "personality => $directory" (required) The name of a directory component on disk. Any files higher in the libraries hierarchy are also loaded, but entries in files contained within this directory, or "closer" to it, will take precedence. "library => $directory | @directories" First library hierarchy, specified either as a single directory or a list of directories that are searched in order. The idea is that this option be set in your application code, perhaps specifying some directory of phrasebooks shipped with the distribution. "add_library => $directory | @directories" Second library hierarchy, specified either as a single directory or a list of directories that are searched in order. This parameter is for the end-user to provide the location(s) of their own phrasebook(s). Any entries found via this path will override those found via the first "library" path. prompt( $name ) Returns the Prompt associated to the given $name, or throws an exception if no such prompt can be found. The returned object is an instance of Net::CLI::Interact::ActionSet. has_prompt( $name ) Returns true if a prompt of the given $name exists in the loaded phrasebooks. prompt_names Returns a list of the names of the current loaded Prompts. macro( $name ) Returns the Macro associated to the given $name, or throws an exception if no such macro can be found. The returned object is an instance of Net::CLI::Interact::ActionSet. has_macro( $name ) Returns true if a macro of the given $name exists in the loaded phrasebooks. macro_names Returns a list of the names of the current loaded Macros. PHRASEBOOK FORMAT
Prompt A Prompt is a named regular expression which matches the content of a single line of text. Here is an example: prompt configure match /(config[^)]*)# ?$/ On the first line is the keyword "prompt" followed by the name of the Prompt, which must be a valid Perl identifier (letters, numbers, underscores only). On the immediately following line is the keyword "match" followed by a regular expression, enclosed in two forward-slash characters. Currently, no alternate bookend characters are supported, nor are regular expression modifiers (such as "xism") outside of the match, but you can of course include them within. The Prompt is used to find out when the connected CLI has emitted all of the response to a command. Try to make the Prompt as specific as possible, including line-end anchors. Remember that it will be matched against one line of text, only. Macro In general, Macros are alternating sequences of commands to send to the connected CLI, and regular expressions to match the end of the returned response. Macros are useful for issueing commands which have intermediate prompts, or confirmation steps. They also support the slurping of additional output when the connected CLI has split the response into pages. At its simplest a Macro can be just one command: macro show_int_br send show ip int br match /> ?$/ On the first line is the keyword "macro" followed by the name of the Macro, which must be a valid Perl identifier (letters, numbers, underscores only). On the immediately following line is the keyword "send" followed by a space and then any text up until the end of the line, and if you want to include whitespace at the beginning or end of the command, use quotes. This text is sent to the connected CLI as a single command statement. The next line contains the keyword "match" followed by the Prompt (regular expression) which will terminate gathering of returned output from the sent command. Macros support the following features: Automatic Matching Normally, you ought always to specify "send" statements along with a following "match" statement so that the module can tell when the output from your command has ended. However you can omit any Match and the module will insert either the current "prompt" value if set by the user, or the last Prompt from the last Macro. So the previous example could be re-written as: macro show_int_br send show ip int br You can have as many "send" statements as you like, and the Match statements will be inserted for you: macro show_int_br_and_timestamp send show ip int br send show clock However it is recommended that this type of sequence be implemented as individual commands (or separate Macros) rather than a single Macro, as it will be easier for you to retrieve the command response(s). Normally the Automatic Matching is used just to allow missing off of the final Match statement when it's the same as the current Prompt. Format Interpolation Each "send" statement is in fact run through Perl's "sprintf" command, so variables may be interpolated into the statement using standard "%" fields. For example: macro show_int_x send show interface %s The method for passing variables into the module upon execution of this Macro is documented in Net::CLI::Interact::Role::Engine. This feature is useful for username/password prompts. Named Match References If you're going to use the same Match (regular expression) in a number of Macros, then set it up as a Prompt (see above) and refer to it by name, instead: prompt priv_exec match /# ?$/ macro to_priv_exec send enable match /[Pp]assword: ?$/ send %s match priv_exec As you can see, in the case of the last Match, we have the keyword "match" followed by the name of a defined Prompt. To match multiple defined Prompts use this syntax (with as many named references as you like): macro to_privileged send enable match username_prompt or priv_exec Continuations Sometimes the connected CLI will not know it's talking to a program and so paginate the output (that is, split it into pages). There is usually a keypress required between each page. This is supported via the following syntax: macro show_run send show running-config follow / --More-- / with ' ' On the line following the "send" statement is the keyword "follow" and a regular expression enclosed in forward-slashes. This is the Match which will, if seen in the command output, trigger the continuation. On the line you then have the keyword "with" followed by a space and some text, until the end of the line. If you need to enclose whitespace use quotes, as in the example. The module will send the continuation text and gobble the matched prompt from the emitted output so you only have one complete piece of text returned, even if split over many pages. The sent text can contain metacharacters such as " " for a newline. Note that in the above example the "follow" statement should be seen as an extension of the "send" statement. There is still an implicit Match prompt added at the end of this Macro, as per Automatic Matching, above. Line Endings Normally all sent command statements are appended with a newline (or the value of "ors", if set). To suppress that feature, use the keyword "put" instead of "send". However this does not prevent the Format Interpolation via "sprintf" as described above (simply use "%%" to get a literal "%"). AUTHOR
Oliver Gorwits <oliver@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Oliver Gorwits. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-12 Net::CLI::Interact::Phrasebook(3pm)
All times are GMT -4. The time now is 03:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy