- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with filter lines in a file
Operating System - HP-UX
1824149
Members
4484
Online
109668
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
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
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
тАО11-26-2003 04:52 AM
тАО11-26-2003 04:52 AM
Help with filter lines in a file
I have a file which has contents as follows
Job: WHALE #PCBSY9LDT Description:
JCL File : ^CBS^/whale/u17/cdb/admin/CDBY9LDT.sh
Logon : cdb Creator: root
Job: WHALE #PCDBD0UTL Description:
JCL File : ^CDB^/whale/u17/cdb/admin/CDBD0UTL.sh
Logon : cdb Creator: root
Job: WHALE #PCDBD0WEB Description:
JCL File : ^CDB^/whale/u17/cdb/admin/CDBD0WEB.sh
Logon : cdb Creator: root
How do I write a shell script that will filter the word say PCDBD0WE and print that line alongwith the 2 more lines below this word?
Thanks
-Andy
Job: WHALE #PCBSY9LDT Description:
JCL File : ^CBS^/whale/u17/cdb/admin/CDBY9LDT.sh
Logon : cdb Creator: root
Job: WHALE #PCDBD0UTL Description:
JCL File : ^CDB^/whale/u17/cdb/admin/CDBD0UTL.sh
Logon : cdb Creator: root
Job: WHALE #PCDBD0WEB Description:
JCL File : ^CDB^/whale/u17/cdb/admin/CDBD0WEB.sh
Logon : cdb Creator: root
How do I write a shell script that will filter the word say PCDBD0WE and print that line alongwith the 2 more lines below this word?
Thanks
-Andy
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2003 05:04 AM
тАО11-26-2003 05:04 AM
Re: Help with filter lines in a file
A simple shell script like the following will do what you want:-
#!/usr/bin/sh
STRING=PCDBD0WE
while read LINE
do
_if___[[ ${LINE} = *(?)${STRING}*(?) ]];
_then_print -- "${LINE}"
______read LINE || break
______print -- "${LINE}"
______read LINE || break
______print -- "${LINE}"
_fi
done
# end of script
Note that I have put underscores in the script for indentation because the ITRC removes leading spaces. Change them to spaces.
Call it (for instance) filterit. Run it as follows:
filterit < yourfile
Regards,
John
#!/usr/bin/sh
STRING=PCDBD0WE
while read LINE
do
_if___[[ ${LINE} = *(?)${STRING}*(?) ]];
_then_print -- "${LINE}"
______read LINE || break
______print -- "${LINE}"
______read LINE || break
______print -- "${LINE}"
_fi
done
# end of script
Note that I have put underscores in the script for indentation because the ITRC removes leading spaces. Change them to spaces.
Call it (for instance) filterit. Run it as follows:
filterit < yourfile
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2003 05:05 AM
тАО11-26-2003 05:05 AM
Re: Help with filter lines in a file
See also:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237288
awk '/PCDBD0WE/{print $0; i=2; while (i--) {getline; print $0}}' <
awk '/
In your case:
awk '/PCDBD0WE/{print $0; i=2; while (i--) {getline; print $0}}' <
Cheers,
Hein.
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
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP