- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk and pattern matching
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
тАО01-23-2003 07:02 AM
тАО01-23-2003 07:02 AM
How do you perform pattern matching with awk using a variable instead of plain text?
example:
awk '{$4="match_this_text" print .....}'
In the example above I want to use a variable name for the string "match_this_text".
Tony
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:10 AM
тАО01-23-2003 07:10 AM
Re: awk and pattern matching
awk '{ if (match($4,"match_this_text") ... }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:24 AM
тАО01-23-2003 07:24 AM
Re: awk and pattern matching
Have you tried just to match the two variables, it should be possible (if you dont have a very old version of awk).
$4 ==
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:28 AM
тАО01-23-2003 07:28 AM
Re: awk and pattern matching
will print all files created witht the date May 7th
I hope this clears the syntax.
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:33 AM
тАО01-23-2003 07:33 AM
Re: awk and pattern matching
Here is an example-
awk '$4~/ab.*yz/{print ...}'
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 07:48 AM
тАО01-23-2003 07:48 AM
Re: awk and pattern matching
awk -v match_this_text=${TEXT_STR} '{if($4 == match_this_string) print .... }' file_name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2003 06:56 AM
тАО08-01-2003 06:56 AM
Re: awk and pattern matching
I made an awk script that generated a new awk script that had all the pattern matches as strings generated from variables in the first script.
Something like:
awk '/to:e-mail addres/ {print "/"$3"/ {what should be done }' > scriptfilename.awk
The final script was made to look someting like:
/first found message ID/ {what should be done}
/other found message ID/ {what should be done}
...
The generated script was run with
awk -f scriptfilename.awk inputfile
With BEGIN and END filters You could also generate BEGIN and END in the second awk script.
Good luck!
Rolf