- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- regular expression in awk
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
05-17-2001 05:18 PM
05-17-2001 05:18 PM
I'm using awk to search for a particular pattern in a text file. The script is very basic as I'm just trying some things currently.
/^2..abc...ANI$/ {print "some text" }
I save the above in a file called awktest and run it using;
awk -f awktest inputfile
Now the problem I am having occurs while I try and anchor the regex with the $ It doesn't produce what I'm expecting
a sample input line in my file would be
2lmabcXYZANI 12345 890 NO
I just want the field "2lmabcXYZANI" but I get no output.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2001 06:00 PM
05-17-2001 06:00 PM
Re: regular expression in awk
You are operating under a misconception about how awk works. In your example, the input record (line) would have to begin with '2' and the line would have to end with 'ANI'. 'ANI' in the middle of the input record does not match. What you need to do is remove the '$' and thus the input record passes the match.
You then would enter a block to process that line and find where your patern begins and ends and print that section. I would use the the built-in functions index or match to find the positions and substr to extract the desired positions followed by a print or printf. You just need a bit more practice with it.
This should get you started, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2001 10:55 PM
05-17-2001 10:55 PM
Re: regular expression in awk
/^2/ && /ANI$/ {print "some text" }
federico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2001 11:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2001 12:22 AM
05-18-2001 12:22 AM
Re: regular expression in awk
awk '/^2..abc...ANI/ {print $1} ' inputfile
this should give you the desired output.
Hope the helps. Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2001 12:45 AM
05-18-2001 12:45 AM
Re: regular expression in awk
awk '
substr ( $1, 1,2 ) == "xxxx" && substr ($1,13,4 ) { print .....}'
See man awk for substr parameters .