- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: parse a file with expressions (grep)
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
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
тАО10-04-2010 07:19 PM
тАО10-04-2010 07:19 PM
Re: parse a file with expressions (grep)
$1 ~ /^'entry1'$/ && $2 ~ /^'entry2'$/ && $3 ~ /^'var'$/ { print "FOUND" }' test.cnf
There is no need for your single quotes around entry1, etc. They aren't doing what you think.
Also, there may be no need to do pattern matching, you could do exact match:
awk -v entry1="${entry1}" -v entry2="${entry2}" -v var="${var}" '
$1 == entry1 && $2 == entry2 && $3 == var { print "FOUND" }' test.cnf
And if you really wanted to do pattern matching you would need to use something like:
$1 ~ /^'$entry1'$/
(And forget about using awk -v.)
Or do:
$1 ~ "^" entry1 "$"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2010 06:20 AM
тАО10-05-2010 06:20 AM
Re: parse a file with expressions (grep)
thx to all for your input, last i have a special question, i add to "test.cnf" following entry:
* * var
and start test.sh (in attachment)
./test.sh entry1 entry2 var
this should find:
entry1 entry2 var
* * var
how can i use "*" in awk ?
regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2010 03:19 AM
тАО10-06-2010 03:19 AM
Re: parse a file with expressions (grep)
>how can I use "*" in awk?
Where are your patterns? On the command line or in your test.cnf?
Do you want to have the command line or test.cnf have EREs? Or do you want an exact match with a special case of "*" in test.cnf?
>if ($1 == /^\*/ && entry2 == /^\*/) {
I have no idea what this will do. == should take either a literal string, number or variable. I guess "/^\*/" is just an expression and it seems to have the value 0 if it doesn't match $0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2010 03:19 AM
тАО10-07-2010 03:19 AM
Re: parse a file with expressions (grep)
@ Where are your patterns? On the command line or in your test.cnf?
in the attachment script (test.sh)
@ Do you want to have the command line or test.cnf have EREs? Or do you want an exact match with a special case of "*" in test.cnf?
i want it , if it easy to handle in test.cnf.
sorry, it explained it very bad .
what i mean :
i want to make an entry in config-file with wildcard's? like :
* * var
and then i want to search with a statement all entry's field 1 and 2 and with exact value in field 3 (example : var)
also i think it complicated to search entries with example
entry* entry* var
but this i don't need for my case.
in the meantime in think about following,
i create a placeholder or wildcard for "*" like "allmatches" and it is
easier to handle in statement's . example:
allmatches allmatches var
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 06:45 PM
тАО10-08-2010 06:45 PM
Solution>I want to search with a statement all entries field 1 and 2 and with exact value in field 3 (example: var)
>I think it complicated to search entries with example: entry* entry* var
>but this I don't need for my case.
Right, this is harder but if you use EREs, you can do that in awk.
>I create a placeholder or wildcard for "*" like "allmatches" and it is easier to handle in statements
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2010 11:21 PM
тАО10-10-2010 11:21 PM
Re: parse a file with expressions (grep)
- « Previous
-
- 1
- 2
- Next »