- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Search Pattern question
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
03-28-2002 07:51 AM
03-28-2002 07:51 AM
Search Pattern question
I have a file like this :
12
13
15
Dest
17
.
.
66
Dest
88
How do I extract/search the word Dest as well as the previous number say for example 15,Dest like that 66,Dest?.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 08:00 AM
03-28-2002 08:00 AM
Re: Search Pattern question
Sandip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 08:01 AM
03-28-2002 08:01 AM
Re: Search Pattern question
Create an awk file, e.g. my.awk
------------
BEGIN {
prev = ""
}
{
if ($0 ~ /Dest/)
{
printf("%s,%s\n",prev,$0)
prev = ""
}
else prev = $0
}
------------
Then cat yourfile | awk -f my.awk > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 08:27 AM
03-28-2002 08:27 AM
Re: Search Pattern question
15 Dest
66 Dest
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 01:09 AM
03-29-2002 01:09 AM
Re: Search Pattern question
Thanks for everyone, Clay's solution worked well and I have already written a shell script for this but I thought there should be some simple command to search multi pattern. Is there any other command or options in grep?
I haven't installed perl on my box.
Thanks
Vasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 01:22 AM
03-29-2002 01:22 AM
Re: Search Pattern question
When you get used to perl, you can forget all about grep, awk, sed, sh, ...
Well, you /could/, but you shouldn't :) There's a good tool for every problem, it only happens that perl fits to most problems
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 01:31 AM
03-29-2002 01:31 AM
Re: Search Pattern question
The usage is as follows:
ngrep -n 1 -p Dest -f
where
-n 1 : get the matching line and 1 line before it
-p Dest : search pattern is "Dest"
-f : filename in which to search.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 01:42 AM
03-29-2002 01:42 AM
Re: Search Pattern question
Seems like there was a problem with the last attachment.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 02:18 AM
03-29-2002 02:18 AM
Re: Search Pattern question
Context control:
-B, --before-context=NUM print NUM lines of leading context
-A, --after-context=NUM print NUM lines of trailing context
-C, --context=NUM print NUM lines of output context
-NUM same as --context=NUM
--color[=WHEN],
--colour[=WHEN] use markers to distinguish the matching string
WHEN may be `always', `never' or `auto'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 02:26 AM
03-29-2002 02:26 AM
Re: Search Pattern question
Thanks for ur response, but the executable is not running on my box. I think some compatibility problem
ERROR:
/usr/lib/dld.sl: Can't open shared library: /usr/lib/libc.2
/usr/lib/dld.sl: No such file or directory
Abort(coredump)
Vasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 02:30 AM
03-29-2002 02:30 AM
Re: Search Pattern question
http://hpux.tn.tudelft.nl/hppd/cgi-bin/redirect?hpux/Languages/perl-5.6.1/perl-5.6.1-sd-10.20.depot.gz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2002 03:16 AM
03-29-2002 03:16 AM
Re: Search Pattern question
awk '{if ($0!="Dest"){ prev=$0 } else printf "%s,%s\n",prev,$0; }' inputfile
It gives:
15,Dest
66,Dest
Regards,
Ceesjan