- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help script parse file
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
Forums
Discussions
Discussions
Discussions
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
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
01-30-2008 09:21 AM
01-30-2008 09:21 AM
in my script input a field pattern: number "node":
example:
----------------------------
./switch
Input number node: 20:20:20:20
-----------------------------
the script found node :20:20:20:20 and display the name of hosts ,and lines:
Type Pid COS PortName NodeName SCR
FC4s: FCP
NodeSymb: [41] "QLA2460 FW:v4.00.23 DVR:v9.1.2.19 (wx64)"
Port Name: 20:20:20:20
Permanent Port Name: 20:20:20:20:
Device type: Physical Initiator
Aliases:
*********** cat log ********************
HOS1
Version 5.1.0d
HOST1 login: user
Password:
user> node 20:20:20:20
No device found
user> Trying 10.10.10.10
Connected to 10.10.10.11
Escape character is '^]'.
HOST2
Version 5.1.0d
HOST2 login: user
Password:
user> node 20:20:20:20
Local:
Type Pid COS PortName NodeName SCR
N 338a00; 3;20:20:20:20:78:58;20:20:20:20; 3
FC4s: FCP
NodeSymb: [41] "QLA2460 FW:v4.00.23 DVR:v9.1.2.19 (wx64)"
Port Name: 20:20:20:20
Permanent Port Name: 20:20:20:20:
Device type: Physical Initiator
Aliases:
... more lines...
HOSTS 3
...
**************************
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 10:16 AM
01-30-2008 10:16 AM
Re: Help script parse file
first close your duplicate thread of the same topic.
The idea is to
- collect data into variables,
- check for your anchor data
- output data after a block delimiter
I assume 2 or more empty lines as a block delimiter
Without coding your request completely, this should lead you to one correct way:
awk -v mynode=20:20:20:20 '$2 == "login:" {host=$1;next}
$2 == "node" {if($3==mynode) node=1;else node=0}
/^Type Pid / {tp=$0;getline;tpdata=$0;next}
# more coding
!NF {empty++;next}
empty && NF {if (node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,mynode,tp,tpdata)
empty=node=0;tp=tpdata=""}' log
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 10:36 AM
01-30-2008 10:36 AM
Re: Help script parse file
It seems to me you simplified that input and output beyond (my) recognition.
If the replies up to this point do not help you enough, then please consider a reply with TEXT attachment with more input, and EXACT output.
- There are a lot of 20:20:20:20 occurences in the input. Which one is the trigger?
- I suspect the line "N 338a00; 3;20:20:20:20:78:58;20:20:20:20; 3" is the trigger. First or second occurance?
- That line is NOT in the sample output. Intentional?
- The words HOSTx are NOT in the output. Intentional?
- Does the first line to display start with 'Type' and the last with 'Aliases'?
- All lines in between, or just some?
Anyway... here is a perl script which seems to do what you currently requested.
See how close it is to what you want!
Enjoy,
Hein.
#!/usr/bin/perl
use strict;
use warnings;
my $LOG = 'cat.log';
my $target = shift or die "Please provide a search target string";
my $found = 0;
my @lines;
open (LOG, "<$LOG") or die "Could not open log file : $LOG\n$!";
while (
@lines = () if /^Type/;
if (/^N.*;$target;/) {
$found++;
} else {
push @lines, $_;
}
if ($found && /^Alias/) {
print @lines;
$found = 0;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 10:54 AM
01-30-2008 10:54 AM
Re: Help script parse file
# mynode=20:20:20:20
# awk -v mynode=20:20:20:20 '$2 == "login:" {host=$1;next} $2 == "node" {if($3==20:20:20:20) node=1;else node=0} /^Type Pid / {tp=$0;getline;tpdata=$0;next} !NF {empty++;next} empty && NF {if (node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,20:20:20:20,tp,tpdata) empty=node=0;tp=tpdata=""}' log
Obtaing :
awk: syntax error near line 1
awk: bailing out near line 1
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 11:04 AM
01-30-2008 11:04 AM
Re: Help script parse file
the log its incomplete
send to original log output
address search 21:00:00:1b:32:06:78:58
the address can be in several name of hosts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 11:30 AM
01-30-2008 11:30 AM
Re: Help script parse file
>> the log its incomplete
Which is exactly how you requested it according to the output example in the base topic. Correct?
Anyhow, it is easier to show it. Change this:
From:
if (/^N.*;$target;/) {
$found++;
} else {
push @lines, $_;
}
To:
$found++ if /^N.*;$target;/
push @lines, $_;
You may also want to change that RSE to /^N.*;$target/
By dropping the final semicolon, you can abbreviate teh node number match string.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2008 12:14 PM
01-30-2008 12:14 PM
Re: Help script parse file
yes its correct , see original log attach in before post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:17 AM
01-31-2008 12:17 AM
Re: Help script parse file
I'm shure my awk works, when corretly formatted. When run not under HP-UX (Solris e.g.) use 'nawk' instead.
awk -v mynode=20:20:20:20 '$2 == "login:" {host=$1;next}
$2 == "node" {if($3==20:20:20:20) node=1;else node=0}
/^Type Pid / {tp=$0;getline;tpdata=$0;next}
!NF {empty++;next}
# the printf-statement is on a single line
empty && NF {if(node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,20:20:20:20,tp,tpdata)
empty=node=0;tp=tpdata=""}' log
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 03:42 AM
01-31-2008 03:42 AM
Re: Help script parse file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 03:57 AM
01-31-2008 03:57 AM
Re: Help script parse file
It doesn't look like it. It is one long string with embedded newlines quoted by ''.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 05:14 AM
01-31-2008 05:14 AM
Solutionmy comment just notified the fact that on the ITRC page the printf-line is seen spread over two lines. If you execute the command, you should put it on only one line.
line1:
awk -v mynode=20:20:20:20 '$2 == "login:" {host=$1;next}
line2:
$2 == "node" {if($3==20:20:20:20) node=1;else node=0}
line3:
/^Type Pid / {tp=$0;getline;tpdata=$0;next}
line4:
!NF {empty++;next}
line5:
empty && NF {if(node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,20:20:20:20,tp,tpdata)
line6:
empty=node=0;tp=tpdata=""}' log
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 06:01 AM
01-31-2008 06:01 AM
Re: Help script parse file
run from solaris 8
# nawk -v mynode=20:20:20:20 '$2 == "login:" {host=$1;next} $2 == "node" {if($3==mynode) node=1;else node=0} /^Type Pid / {tp=$0;getline;tpdata=$0;next} !NF {empty++;next} empty && NF {if (node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,mynode,tp,tpdata) empty=node=0;tp=tpdata=""}' cat.log
nawk: syntax error at source line 1
context is
$2 == "login:" {host=$1;next} $2 == "node" {if($3==mynode) node=1;else node=0} /^Type Pid / {tp=$0;getline;tpdata=$0;next} !NF {empty++;next} empty && NF {if (node && empty) printf("Host %s\nnode %s\n%s\n%s\n",host,mynode,tp,tpdata) >>> empty <<< =node=0;tp=tpdata=""}
nawk: illegal statement at source line 1
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 07:23 AM
01-31-2008 07:23 AM
Re: Help script parse file
it seems, you insist in putting all awk statements into one line (why?).
If you do not want to use the line layout of my previous post, the last error message you sent could be resolved in putting a semicolon before the 'empty=...' statement:
...,mynode,tp,tpdata); empty=node=...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 11:28 AM
01-31-2008 11:28 AM
Re: Help script parse file
see attacht in post before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 11:40 AM
01-31-2008 11:40 AM
Re: Help script parse file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:15 PM
01-31-2008 12:15 PM
Re: Help script parse file
I'm shure, you can do this by yourself.
You've got the idea for parsing such a file - now is the time for YOU to do the homeworks.
Some helpful comments:
- change 'node' to 'nodefind'
- lever the condition for 'Type Pid' to be located at the beginning of a line, so that there may be some spaces before:
/^ *Type Pid /
- add more pattern-action lines to this code to collect all required output.
Have fun!
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:17 PM
01-31-2008 12:17 PM
Re: Help script parse file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:17 PM
01-31-2008 12:17 PM
Re: Help script parse file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:19 PM
01-31-2008 12:19 PM
Re: Help script parse file
I change node for nodefind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:26 PM
01-31-2008 12:26 PM
Re: Help script parse file
backup2# ./test1
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Type Pid COS PortName NodeName SCR
N 338a00; 3;21:00:00:1b:32:06:78:58;20:00:00:1b:32:06:78:58; 3
Host login:
node 21:00:00:1b:32:06:78:58
Type Pid COS PortName NodeName
N 338a00; 3;21:00:00:1b:32:06:78:58;20:00:00:1b:32:06:78:58;
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Host login:
node 21:00:00:1b:32:06:78:58
Type Pid COS PortName NodeName SCR
N 338a00; 3;21:00:00:1b:32:06:78:58;20:00:00:1b:32:06:78:58; 3
backup2#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2008 12:28 PM
01-31-2008 12:28 PM