dls0
IS-IT--Management
- Mar 19, 2008
- 2
Hello to all,
I am new at learning awk and want to make sure that the kind of problem I face can be solved within awk so I am not wasting my time.
My problem is conceptually simple:
I want to match a string using a regex pattern and have awk print out only the field(s) that matches the pattern and not the entire line.
Here is the hard part for me.
I will not know ahead of time exactly which field $1 - $NF it is going to match and the field within the line that matches can vary from file to file so, I need awk "to know" that it doesn't matter what field within the line that matches but print only the fields that match and not the entire line on which the matching field occurs.But I can't specify before hand which field(s) to print because it will vary.
I need to extract specific field values over several thousand files and I hope that awk would let me write the script in a way where I don't have to know ahead of time which field on which line will match.
I know awk can easily match fields and print out the line that matches. And I know that awk can easily print out just those fields that one specifies when a match occurs.
I need awk to allow the field location to vary and know just give me the field when they match the regex and not the entire line.
Something like this.
Match regex pattern P in any field on any line it occurs in file_1 through file_n.
Print only the field value(s) that matches the regex pattern P.
I hope I was clear. I don't expect anyone to show me how to do this but if anyone would be so kind just to answer whether this is indeed something awk can do I would be relieved to know I am not wasting my time as I move forward trying to learn awk to solve this kind of problem.
Thanks,
dls0
I am new at learning awk and want to make sure that the kind of problem I face can be solved within awk so I am not wasting my time.
My problem is conceptually simple:
I want to match a string using a regex pattern and have awk print out only the field(s) that matches the pattern and not the entire line.
Here is the hard part for me.
I will not know ahead of time exactly which field $1 - $NF it is going to match and the field within the line that matches can vary from file to file so, I need awk "to know" that it doesn't matter what field within the line that matches but print only the fields that match and not the entire line on which the matching field occurs.But I can't specify before hand which field(s) to print because it will vary.
I need to extract specific field values over several thousand files and I hope that awk would let me write the script in a way where I don't have to know ahead of time which field on which line will match.
I know awk can easily match fields and print out the line that matches. And I know that awk can easily print out just those fields that one specifies when a match occurs.
I need awk to allow the field location to vary and know just give me the field when they match the regex and not the entire line.
Something like this.
Match regex pattern P in any field on any line it occurs in file_1 through file_n.
Print only the field value(s) that matches the regex pattern P.
I hope I was clear. I don't expect anyone to show me how to do this but if anyone would be so kind just to answer whether this is indeed something awk can do I would be relieved to know I am not wasting my time as I move forward trying to learn awk to solve this kind of problem.
Thanks,
dls0