- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl pattern searching - help needed
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
11-28-2003 11:42 AM
11-28-2003 11:42 AM
I have a perl statement in a UNIX Shell script. I am using the perl statement for pattern maching.I have got the pattern in an UNIX variable 'x'. I want to use this variable for the pattern searching in the perl statement which is like:
perl -ne 'if (/pattern/) {.....}
I want the pattern to have the value of 'x'. Is it possible.
Thanks,
Andy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2003 11:51 AM
11-28-2003 11:51 AM
Re: Perl pattern searching - help needed
i.e.
perl -ne 'if (/$x/) {.....}
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2003 11:54 AM
11-28-2003 11:54 AM
Re: Perl pattern searching - help needed
I have tried using $x but it doesn't work.
-Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2003 11:58 AM
11-28-2003 11:58 AM
Re: Perl pattern searching - help needed
I think the following link might help you,
http://zamov.online.fr/EXHTML/Perl/Perl_27283.html
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2003 01:24 PM
11-28-2003 01:24 PM
Re: Perl pattern searching - help needed
I tried the following and it works,
---------
#!/usr/bin/perl
if ( $#ARGV != 1 )
{
print "Usage: test.pl string_to_searched string\n";
}
else
{
$x = $ARGV[0];
$test = $ARGV[1];
if ( $test =~ /$x/ )
{
print "String contains $x in it! \n";
}
else
{ print "I am Sorry!! $x is not found in string \n";
}
}
--------------
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2003 10:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2003 10:45 AM
11-30-2003 10:45 AM
Re: Perl pattern searching - help needed
Here is an example with pattern matching.
[dev] # x=xyz
[dev] # export x
[dev] # perl -e 'if ("uvwxyz" =~ /$ENV{var}/){print "match\n";}else{print "no match\n";}'
match
[dev] # perl -e 'if ("uvwyz" =~ /$ENV{var}/){print "match\n";}else{print "no match\n";}'
no match
[dev] #
Cheers,
JW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2003 10:56 AM
11-30-2003 10:56 AM
Re: Perl pattern searching - help needed
[dev] # x=xyz
[dev] # export x
[dev] # echo $x
xyz
[dev] # perl -e 'print "uvwxyz" =~ /$ENV{x}/ ? "Yes\n" : "No\n";'
Yes
[dev] # perl -e 'print "uvwyz" =~ /$ENV{x}/ ? "Yes\n" : "No\n";'
No
[dev] #
JW.