- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- pattern search (shell script)
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
08-29-2002 04:20 AM
08-29-2002 04:20 AM
pattern search (shell script)
Can anybody tell me how to do a pattern search for more than one character... example: I want search words whose last character is "c" or "h" or "at".
Thanx in advance!
-Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:22 AM
08-29-2002 04:22 AM
Re: pattern search (shell script)
*c|*h|*at) : blah
;;
*x|*fdg|*gurgl) : booh
;;
*) exit ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:25 AM
08-29-2002 04:25 AM
Re: pattern search (shell script)
man grep
cat file | grep -e "at" -e "h" -e "c"
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:29 AM
08-29-2002 04:29 AM
Re: pattern search (shell script)
# ls -1 | egrep '(c|h|at)$'
And 'cat' is (again) completely redundant and only cluttering the resources with an extra process:
# grep -e at -e h -e c < file
would perform your action a lot faster if the system is close to it's process limit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:35 AM
08-29-2002 04:35 AM
Re: pattern search (shell script)
This is if the filter is to be applied on the output of a program/application.
I simulated this pgm with cat file
otherwise
grep -e "at" -e "h" -e "c" filename
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:38 AM
08-29-2002 04:38 AM
Re: pattern search (shell script)
here's an example:
cat somefile | grep -e "c$" -e "h$" -e "at$"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:44 AM
08-29-2002 04:44 AM
Re: pattern search (shell script)
Harry, actually I wanted to findout all the words from the text file which ends with "c", "h" or "at" (two chars).
Thanks.
-Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:50 AM
08-29-2002 04:50 AM
Re: pattern search (shell script)
WORDS is the keyword here!
try this
cat YOURFILE | grep -e "[c|h][ |$]" -e "at[ |$]"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 04:59 AM
08-29-2002 04:59 AM
Re: pattern search (shell script)
Can I list the files (using ls) and combing your regular expression but with not using grep? ls command should list only the files which ends with c or h or at. I do not want to use command like "ls *c *h *at". Here you can also use find command, which will be better.
After the output of this command, I want to pass it to grep which will find the specific words in these files.
-Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 05:03 AM
08-29-2002 05:03 AM
Re: pattern search (shell script)
Words:
perl -nle '$w{$1}++while/\b(\w+(?:a|t|ch))\b/g;END{print"$_ ($w{$_})"for sort keys%w}' file
Sentences:
perl -ne '/(a|t|ch)\b/ and print' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 05:08 AM
08-29-2002 05:08 AM
Re: pattern search (shell script)
Yes,
cd 2directory2search
find . -type f -name "*[c|h]$" -o -name "*at$" -exec grep -l WORDPATTERN_HERE {} \;
example:
cd 2directory2search
find . -type f -name "*[c|h]$" -o -name "*at$" -exec grep -l "[Ss]anjay[ |$]" {} \;
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2002 05:42 AM
08-29-2002 05:42 AM
Re: pattern search (shell script)
# cd 2directory2search
# perl -MFile::Find -nle
'find(sub{-f&&-s&&/(a|t|ch)$/ or return;local$/;open F,"<$_"or return;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2002 02:46 PM
09-03-2002 02:46 PM
Re: pattern search (shell script)
find . -type f -name '*.{c,h,at}' | xargs grep -Ff tfile