- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Multiple word 'grep' in perl
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
Discussions
Discussions
Discussions
Forums
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
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
тАО09-28-2001 05:04 AM
тАО09-28-2001 05:04 AM
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2001 05:23 AM
тАО09-28-2001 05:23 AM
Re: Multiple word 'grep' in perl
If I run the following perl script:
#!/opt/perl5/bin/perl
@words=qw(mary had a little lamb);
@matches=grep /(m|b)/, @words;
$match=grep /(m|b)/, @words;
print "$match,@matches\n";
I get the following result:
2,mary lamb
Is this what you are after?
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2001 05:59 AM
тАО09-28-2001 05:59 AM
Re: Multiple word 'grep' in perl
Thanks for your reply, the question I have is how to grep for a multiple word string in a file and know its result.
Sorry, may be the question that I asked is too abstract. I will put it a little better this time.
There is a file by name aaa which contain name, both first name and second name. In perl we can use the command
-----------------------------
system("grep /'$name/' aaa");
-----------------------------
where $name is a variabe having name of a person such as "Anil Bhat" and aaa is the filename.
To know the result we can see the $? variable. But this is returning 256 every time.
Thanks and regards,
Umesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2001 06:18 AM
тАО09-28-2001 06:18 AM
SolutionDid you instead want back-slashes-- \'$name\' to protect the single quote?
The slashes are being passed as part of the string to grep, just use '$name'. Since you started you literal string with double quote, the single quotes do not need any special "escapes".
-- Rod H
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2001 07:01 AM
тАО09-28-2001 07:01 AM
Re: Multiple word 'grep' in perl
I created a script containing:
#!/usr/bin/perl
$file="/tmp/grep.in";
$name="robin wakefield";
system ("grep '$name' $file");
print $?,"\n";
When "robin wakefield" is found, $?=0
When it isn't found $?=256
I think you should remove the / characters.
Rgds, robin.