Sponsored Content
Full Discussion: How to parse..
Top Forums Shell Programming and Scripting How to parse.. Post 35928 by criglerj on Wednesday 14th of May 2003 09:41:04 AM
Old 05-14-2003
Assuming your awk is nawk, you can (probably) do this:
Code:
tnsping PROD | awk '/Attempting/ {
        s = toupper($0)
        if (!match(s, /PORT=[0-9]+/)
            print "Where's the port?" > "/dev/tty"
            exit(1)
        else
            port = substr(s, RSTART+5, RLENGTH-5)
    }' | read port
echo "port = " $port

The regexp may need to be adjusted to /PORT=[0-9][0-9]*/ if your awk doesn't like the +.

If your output may actually come out on multiple lines per the formatting of your original post, but the "port=" and its port number will always be on the same line, you can shortcut the above this way:
Code:
tnsping PROD | awk 'match(toupper($0), /PORT=[0-9]+/) {
        print substr($0, RSTART+5, RLENGTH-5)
}' | read port
echo "port = " $port

The secret here is to realize that the pattern does not have to be a regular expression. Be a little careful: There's only one RSTART/RLENGTH pair, so more than one "match" in an expression (in the pattern or the action) will only get set RSTART & RLENGTH for the last "match" evaluated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse

Does anybody know how do we parse a file (ex. SIF file) into a delimited text file in UNIX? (7 Replies)
Discussion started by: nguda
7 Replies

2. UNIX for Advanced & Expert Users

Parse error

hi,:) onsider the followinf two lines J="$(scriptbc -p 8 $I / \(12 \* 100 \) )" N="$(( $L * 12 ))" In the first line I put \ before * like \* and its working fine. But in the second line if put \ before * i am getting parse error. What might be the reason?Any idea pls. cheers RRK (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

3. Shell Programming and Scripting

Need help to parse the file

# Start "ABC" SFFd 0 4 Time SFFT 4 8 {Sec} User SFFTimeVal 12 8 {Sec} # Start "CP" SFFT ... (3 Replies)
Discussion started by: navsharan
3 Replies

4. Shell Programming and Scripting

Parse

I need a script that will always return an engine of table, which not depends on the table structure. I need it to be done exactly from the "show create table ..." statement. If there is a easiest way, except "show table status", please write. mysql -u root db -sBe "show create table... (1 Reply)
Discussion started by: mirusnet
1 Replies

5. Shell Programming and Scripting

Perl Parse

Hi I'm writing simple perl script to parse the ftp log as below: Local directory now /home/user/testing 227 Entering Passive Mode (192,254,19,34,8,228). 125 Data connection already open; Transfer starting. 09-25-09 02:33PM 25333629 abc.tar 09-14-09 12:50PM 18015752... (1 Reply)
Discussion started by: netxus
1 Replies

6. Shell Programming and Scripting

How to Parse a Prompt?

On the command, when I type in certain commands, they will display a prompt waiting for some input. When I type in the requested input, it will display the info I requested. For example, if I enter the telnet command, it will display a telnet prompt and wait for me to enter something. I... (1 Reply)
Discussion started by: april
1 Replies

7. Shell Programming and Scripting

Parse 2 or more files into one.

Hi, I have a really simple question...I think. I want to be able to parse two or more files into one by reading the first record from each file into new file then go back to the first file and start reading the second record in from each file into new file and so on. I am new to using awk and am... (5 Replies)
Discussion started by: qray2011
5 Replies

8. Shell Programming and Scripting

Parse

Attached file is parsed so that only the three columns result. DACH1 occurs 34 times with an average of 0.881541 NEB occurs 159 times with an average of 0.837628 LTBP1 occurs 46 times with an average of 0.748722 parse result: output.txt (the text is removed and the xxx is seperated in a... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. Shell Programming and Scripting

Parse html

I downloaded source code using: wget -qO- http://fulgentdiagnostics.com/test/clinical-exome/ | cat > flugentsource.txt Now I am trying to use sed to parse it to confirm a gene count. Basically, output (flugent.txt) all the gene names with a total count after them I'm not all that... (5 Replies)
Discussion started by: cmccabe
5 Replies

10. Programming

Parse with SQL

I am trying to parse a string using SQL but am too new and still learning. I have text in a control or field 685 that is variable, but always the same format. field 685 input arr 2q33.3q34(200,900,700-209,000,000)x2 xxx Desired output 2:200900700-209000000 Basically, the # after the... (2 Replies)
Discussion started by: cmccabe
2 Replies
snmp_community_mib(3erl)				     Erlang Module Definition					  snmp_community_mib(3erl)

NAME
snmp_community_mib - Instrumentation Functions for SNMP-COMMUNITY-MIB DESCRIPTION
The module snmp_community_mib implements the instrumentation functions for the SNMP-COMMUNITY-MIB, and functions for configuring the data- base. The configuration files are described in the SNMP User's Manual. EXPORTS
configure(ConfDir) -> void() Types ConfDir = string() This function is called from the supervisor at system start-up. Inserts all data in the configuration files into the database and destroys all old rows with StorageType volatile . The rows created from the configuration file will have StorageType nonVolatile . All snmp counters are set to zero. If an error is found in the configuration file, it is reported using the function config_err/2 of the error, report module and the function fails with reason configuration_error . ConfDir is a string which points to the directory where the configuration files are found. The configuration file read is: community.conf . reconfigure(ConfDir) -> void() Types ConfDir = string() Inserts all data in the configuration files into the database and destroys all old data, including the rows with StorageType non- Volatile . The rows created from the configuration file will have StorageType nonVolatile . Thus, the data in the SNMP-COMMUNITY-MIB, after this function has been called, is from the configuration files. All snmp counters are set to zero. If an error is found in the configuration file, it is reported using the function config_err/2 of the error report module, and the function fails with reason configuration_error . ConfDir is a string which points to the directory where the configuration files are found. The configuration file read is: community.conf . add_community(Idx, CommName, SecName, CtxName, TransportTag) -> Ret Types Idx = string() CommName = string() SecName = string() CtxName = string() TransportTag = string() Ret = {ok, Key} | {error, Reason} Key = term() Reason = term() Adds a community to the agent config. Equivalent to one line in the community.conf file. delete_community(Key) -> Ret Types Key = term() Ret = ok | {error, Reason} Reason = term() Delete a community from the agent config. Ericsson AB snmp 4.19 snmp_community_mib(3erl)
All times are GMT -4. The time now is 03:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy