- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- parse a file with expressions (*)
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
01-05-2012 06:52 AM
01-05-2012 06:52 AM
hello,
i have a new question to :
parse a file with expressions (grep)
the awk is perfect:
No, "*" is easier:
# Pattern in test.cnf
# Use == for match
awk -v entry1="${entry1}" -v entry2="${entry2}" -v var="${var}" '
($1 == "*" || $1 == entry1) &&
($2 == "*" || $2 == entry2) &&
$3 == var { print "FOUND5:", $0 }' test.cnf
and handle entry in "test.cnf" like:
* entry2
entry entry2
but how can i handle entries with "characters*" like in "test.cnf" :
demo* entry
is it possible to handle entries with "*" and "character*" ([a-z]*) and a exact entry ?
regards
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2012 07:40 AM
01-06-2012 07:40 AM
Re: parse a file with expressions (*)
>demo* entry
>is it possible to handle entries with "*" and "character*" ([a-z]*) and a exact entry?
I'm not sure what you want? Do you want to treat "*" as a normal character or as a shell pattern match?
Your above awk fragment treats it as a normal char but with special processing, to pretend to be a pattern.
If you want to do more general pattern matching, you would have to use system to invoke a shell.
Or you could convert that pattern into a regex an use awk's ERE to do the matching.
demo* (pattern) == demo.* (regex)
demo? (pattern) == demo. (regex)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2012 07:01 AM
01-09-2012 07:01 AM
Re: parse a file with expressions (*)
hello,
If you want to do more general pattern matching, you would have to use system to invoke a shell. Or you could convert that pattern into a regex an use awk's ERE to do the matching. demo* (pattern) == demo.* (regex) demo? (pattern) == demo. (regex)
right, i want to extend "awk" and want to handle
"*"
"demo*"
"demo"
for example
"*" and "demo" is perfect with the awk , but how i handle like "demo*"
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2012 07:48 PM
01-09-2012 07:48 PM
Solution>I want to extend "awk" and want to handle: "*", "demo*", "demo"
As I suggested, you convert the pattern to a ERE then try matching:
awk -v entry1="${entry1}" -v entry2="${entry2}" -v var="${var}" '
function to_ere(pattern) {
# convert from *, ? pattern to ERE, add anchors
gsub("\*", ".*", pattern)
gsub("\?", ".", pattern)
pattern = "^" pattern "$"
return pattern
}
$3 == var {
ere1 = to_ere($1)
ere2 = to_ere($2)
if (entry1 ~ ere1 && entry2 ~ ere2) {
print "FOUND5:", $0
}
}' test.cnf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2012 01:52 AM
01-10-2012 01:52 AM
Re: parse a file with expressions (*)
thank you very much, perfect solution with ERE ( i learn every day when you post solutions)