HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: question on grep command
Operating System - HP-UX
1833776
Members
2522
Online
110063
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
Go to solution
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
02-22-2002 02:02 PM
02-22-2002 02:02 PM
I am working on HP-UX
I have a file as follows
Record 1
--------
Name:
address:
Phone:
Phone:
Record 2
--------
.
From the above in shell programming How do i grep for the first occurance of the string "phone:". Any body can help
Thanks
Narasimham
I have a file as follows
Record 1
--------
Name:
address:
Phone:
Phone:
Record 2
--------
.
From the above in shell programming How do i grep for the first occurance of the string "phone:". Any body can help
Thanks
Narasimham
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2002 02:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2002 02:12 PM
02-22-2002 02:12 PM
Re: question on grep command
This is a little bit more complicated if what you really want, is the first 'Phone:' after each 'Name:'. If that is the case, then a little bit of Perl or Awk will be your best bet. Is this what you are really trying to do?
Regards, Clay
Regards, Clay
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2002 02:10 AM
02-27-2002 02:10 AM
Re: question on grep command
1. With grep, you can also add '-i' for case-insensative searches Phone vs phone
2. To get the first Phone: from each /Record:/
perl -ne '/^Record\s+(\d+)/ and $rn=$1,next;$rn&&/^Phone/i or next;print;$rn=0;' datafile
2. To get the first Phone: from each /Record:/
perl -ne '/^Record\s+(\d+)/ and $rn=$1,next;$rn&&/^Phone/i or next;print;$rn=0;' datafile
Enjoy, Have FUN! H.Merijn
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