- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Grep in AWK
Operating System - Linux
1753886
Members
7102
Online
108809
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО08-10-2006 08:04 PM
тАО08-10-2006 08:04 PM
Re: Grep in AWK
Hi Praveen,
The same problem I am also encountered.
And I am also searching for the same solution.
the last solution you got seem to be a good one but it is not working for me and I could not able to understand
f1[ii] = $NF
If something worked for you then kindly post it to me.
Thanks advanced,
Regards,
Anantha Ganiga
The same problem I am also encountered.
And I am also searching for the same solution.
the last solution you got seem to be a good one but it is not working for me and I could not able to understand
f1[ii] = $NF
If something worked for you then kindly post it to me.
Thanks advanced,
Regards,
Anantha Ganiga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2006 12:28 AM
тАО08-11-2006 12:28 AM
Re: Grep in AWK
Hi,
the assignment of the arry elements should read as
f1[ii] = $NF
The whole script I would change to
- a pure awk script
- not ignoring case sensivity
- include some flexibility
file get_bs_of_a.awk:
#!/usr/bin/awk
BEGIN{ while (getline < "b") f1[++ii] = $NF}
found_in_a { mypatt=$0
for( j=1; jj <=ii; jj++) if(index(mypatt, f1[jj]) {print "in a: "$0,"in b: "f1[j]"}
execute as
get_bs_of_a.awk a
What is done:
In the BEGIN statement you once collect the content of file "b" in an array - i.e. the file you lookup for matching pattern of file "a" is processed only once. If you need only a part of the file or of a line, assign the required value only.
found_in_a
is your condition for matching lines of "a" you want to lookup in "b"; it could be something like
/mypattern/
$3 == "wow"
NF == 42
or you just leave it to get every line.
mypatt=
this selects the string you want to 'grep' for in "b";
mypatt=$0 searches the whole line
mypatt=$3"-"$4"-"$5" searches for '-'seperated values of field 3 to 5.
index function
if you do not need pattern for matching but a simple string, index() is your friend. If you need a regexp, use the match operator "~" or the match() function.
mfG Peter
the assignment of the arry elements should read as
f1[ii] = $NF
The whole script I would change to
- a pure awk script
- not ignoring case sensivity
- include some flexibility
file get_bs_of_a.awk:
#!/usr/bin/awk
BEGIN{ while (getline < "b") f1[++ii] = $NF}
found_in_a { mypatt=$0
for( j=1; jj <=ii; jj++) if(index(mypatt, f1[jj]) {print "in a: "$0,"in b: "f1[j]"}
execute as
get_bs_of_a.awk a
What is done:
In the BEGIN statement you once collect the content of file "b" in an array - i.e. the file you lookup for matching pattern of file "a" is processed only once. If you need only a part of the file or of a line, assign the required value only.
found_in_a
is your condition for matching lines of "a" you want to lookup in "b"; it could be something like
/mypattern/
$3 == "wow"
NF == 42
or you just leave it to get every line.
mypatt=
this selects the string you want to 'grep' for in "b";
mypatt=$0 searches the whole line
mypatt=$3"-"$4"-"$5" searches for '-'seperated values of field 3 to 5.
index function
if you do not need pattern for matching but a simple string, index() is your friend. If you need a regexp, use the match operator "~" or the match() function.
mfG Peter
The Universe is a pretty big place,
it's bigger than anything anyone has ever dreamed of before.
So if it's just us, seems like an awful waste of space, right?
Jodie Foster in "Contact"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 07:27 AM
тАО09-05-2006 07:27 AM
Re: Grep in AWK
I do something pretty simple.
if I am looking for a particular string in a field, I do the following.
This example looks at output from ONSTAT and prints output. In this example I filter out data prior to running it against AWK as it reduces processing time by doing so.
onstat -u |grep -v informix|grep -v total |awk '{print $9, $4, $5, $10, $11}' |sort -n |tail -10
if I am looking for a particular string in a field, I do the following.
This example looks at output from ONSTAT and prints output. In this example I filter out data prior to running it against AWK as it reduces processing time by doing so.
onstat -u |grep -v informix|grep -v total |awk '{print $9, $4, $5, $10, $11}' |sort -n |tail -10
- « Previous
-
- 1
- 2
- Next »
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP