HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: help lines script
Operating System - Linux
1828853
Members
2424
Online
109985
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
04-09-2008 09:09 AM
04-09-2008 09:09 AM
help lines script
Hi, I have this lines , my patern to find is example: 50:06:04:8c:52:a5:62:88 , I need extract the two previos lines
include Name hosts
zone: HOSTB-SRV:8b_1
20:00:00:e0:69:41:4c:3f
50:06:04:84:49:af:03:a7
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
50:06:04:8c:52:a5:62:88
awk '/50:06:04:8c:52:a5:62:88/' output.tmp
50:06:04:8c:52:a5:62:88
grep "50:06:04:8c:52:a5:62:88" output.tmp
50:06:04:8c:52:a5:62:88
include Name hosts
zone: HOSTB-SRV:8b_1
20:00:00:e0:69:41:4c:3f
50:06:04:84:49:af:03:a7
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
50:06:04:8c:52:a5:62:88
awk '/50:06:04:8c:52:a5:62:88/' output.tmp
50:06:04:8c:52:a5:62:88
grep "50:06:04:8c:52:a5:62:88" output.tmp
50:06:04:8c:52:a5:62:88
legionx
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2008 09:43 AM
04-09-2008 09:43 AM
Re: help lines script
Just have awk stash away the lines as it read them , for example in l2 and l1 and print those on match.
With hard-coded match:
$ awk '/50:06:04:8c:52:a5:62:88/{print l2; print l1} {l2=l1;l1=$0}' x
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
Using a variable to look for...
$ id="50:06:04:8c:52:a5:62:88"
$ awk -vid=$id '$1==id {print l2; print l1} {l2=l1;l1=$0}' x
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
hth,
Hein.
With hard-coded match:
$ awk '/50:06:04:8c:52:a5:62:88/{print l2; print l1} {l2=l1;l1=$0}' x
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
Using a variable to look for...
$ id="50:06:04:8c:52:a5:62:88"
$ awk -vid=$id '$1==id {print l2; print l1} {l2=l1;l1=$0}' x
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
hth,
Hein.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2008 10:20 AM
04-09-2008 10:20 AM
Re: help lines script
Hi:
One way (in Perl):
perl -e '@lines=reverse (<>);for (@lines) {push @rslt,$_ if /^50:06:04:8c/../^zone/};print reverse @rslt' file
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
50:06:04:8c:52:a5:62:88
Regards!
...JRF...
One way (in Perl):
perl -e '@lines=reverse (<>);for (@lines) {push @rslt,$_ if /^50:06:04:8c/../^zone/};print reverse @rslt' file
zone: HOSTA-SRV:9c0
20:00:00:e0:69:41:4c:3f
50:06:04:8c:52:a5:62:88
Regards!
...JRF...
- Tags:
- Perl
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP