- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: getting info between 2 fields
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
тАО09-19-2007 02:29 AM
тАО09-19-2007 02:29 AM
I am attempting to get all information between two strings when a certain field is equal to Wed Sep 19.
here is an example of the data in the file (nb this is on AIX O/S)
LABEL: VPATH_PATH_OPEN
IDENTIFIER: F45CFAFB
Date/Time: Wed Sep 19 15:00:23 BST 2007
Sequence Number: 316081
Machine Id: 00C84A6D4C00
Node Id: pace
Class: H
Type: PERM
Resource Name: hdisk22
Resource Class: disk
Resource Type: 2107
Location: U787B.001.DNW3DCD-P1-C2-T1-W500507630518C473-L4031400800000000
VPD:
Manufacturer................IBM
Machine Type and Model......2107900
Serial Number...............75FDFW13108
EC Level.....................309
Device Specific.(Z0)........10
Device Specific.(Z1)........0303
Device Specific.(Z2)........075
Device Specific.(Z3)........30806
Device Specific.(Z4)........08
Device Specific.(Z5)........00
Description
OPEN FAILURE
Probable Causes
DISK
SCSI ADAPTER
SCSI CABLE
Failure Causes
DISK
SCSI ADAPTER
CABLE LOOSE OR DEFECTIVE
Recommended Actions
PERFORM PROBLEM DETERMINATION ON SCSI TARGET DEVICE
PERFORM PROBLEM DETERMINATION ON HOST SCSI ADAPTER
REPLACE SCSI CABLE
Detail Data
SENSE DATA
0000 0000 8000 002A 0000 0012 0000 0003 0000 0001 0000 0000 0000 0005
so when todays date is found I would like to print all information between LABEL: and SENSE DATA.
any help will be greatly appreciated.
Thanks Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 02:43 AM
тАО09-19-2007 02:43 AM
Re: getting info between 2 fields
errpt -a |awk -F":" '/Date\/Time/ {if ($2 ~ /Wed Sep 19/) {print}}'
thanks again
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 03:18 AM
тАО09-19-2007 03:18 AM
Re: getting info between 2 fields
If you found the date use this.
START="LABEL"
END="SENSE DATA"
read=0
for line in $(cat yourfile) ; do
if [ "${line}" = "${START}" ]
read=1
fi
if [ ${read} -eq 1 ]
then
echo ${line}
fi
if [ "${line}" = "${END}" ]
read=0
fi
done
not tested just a brain dump
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 04:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 05:01 AM
тАО09-19-2007 05:01 AM
Re: getting info between 2 fields
Try thisL:
# cat ./filter
#!/usr/bin/perl
use strict;
use warnings;
my @a;
my $toggle = 0;
my $target = shift;
while (<>) {
push @a, $_ if /^LABEL|^IDENTIFIER|^\s*$/;
if (/^Date/) {
if (/$target/) {
$toggle++;
print for @a;
@a = ();
}
else {
$toggle = 0;
@a = ();
}
}
if ($toggle) {
if (/^SENSE/) {
print;
$_ = <>;
print;
$toggle = 0;
}
else {
print;
}
}
}
1;
...Run this passing two arguments. The first is a QUOTED (single or double) string defining your target date. The second argument is the name of the file containing the data to be parsed:
# ./filter 'Sep 19' logfile
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 05:02 AM
тАО09-19-2007 05:02 AM
Re: getting info between 2 fields
awk '
/^LABEL/ {label= $0;}
/the date/ {label =. $0;date = "found"}
{label =. $0;}
/^SENSE/ {label =. $0;if (date ~ "found" ) {printf("%s",label);date = "done";}
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 05:08 AM
тАО09-19-2007 05:08 AM
Re: getting info between 2 fields
my solution uses the strings LABEL and SENSE DATA as block markers. I store all upto the date/time line in an array, which is printed when there is a match, the rest of the block is directly printed.
The matching pattern is generated by the date command and fed into an awk variable.
awk -v m="$(date '+%b %d .* %Y')" '/^LABEL/ {what=-1;next}
what<0 {keep[lino++]=$0}
/^Date\/Time: / {if($0 ~ m) {what=1;for(i=0;i
/^SENSE DATA/ {what=0;lino=0}
what>0' /tmp/inputdata
I would prefer to skip the line 'Detail Data' additionally - just replace
/^SENSE DATA/ {what=0;lino=0}
by
/^Detail Data {what=0;lino=0}
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 05:15 AM
тАО09-19-2007 05:15 AM
Re: getting info between 2 fields
anyway there is no =. in awk.
you'll need to replace the concatenations like this:
label =. $0;
should be:
label = (label $0);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 05:23 AM
тАО09-19-2007 05:23 AM
Re: getting info between 2 fields
this should work just as well
awk '
{label = (label $0);}
/^LABEL/ {label = $0;}
/the date/ {date = "found";}
/^SENSE/ {if (date ~ "found" )
{printf("%s",label);
date = "done";}
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 11:53 AM
тАО09-19-2007 11:53 AM
Re: getting info between 2 fields
awk '
{
if ($0~dt) flg++
if ($0~"LABEL:") start++
if ($0~"SENSE DATA")
{
if (flg) {print lst;lst="";flg=0;start=0}
else {lst="";start=0}
}
if (start) lst=(lst?lst"\n"$0:$0)
}' dt="$(date +"%a %b %d")" file