contrace...@gmail.com wrote: > Hi: > Is there any way to make a grep using awk > to find a specified string between "-------------" and > "--------------" lines ?
> contrace...@gmail.com wrote: > > Hi: > > Is there any way to make a grep using awk > > to find a specified string between "-------------" and > > "--------------" lines ?
No, that's not how you pass the value of shell variables to an awk script. See question 24 in the comp.unix.shell FAQ (http:// cfaj.freeshell.org/shell/cus-faq-2.html#24).
In article <a41c5c09-c8f8-4958-a502-fa99f9051...@m22g2000vbl.googlegroups.com>, Ed Morton <mortons...@gmail.com> wrote: ...
>No, that's not how you pass the value of shell variables to an awk >script. Blah, blah, blah.
No, that *is* how he passes shell variables to an AWK script. It also happens to be how I (usually) do it.
It may not be how you (Ed) do it, but then again, it takes all kinds to make a world. Diversity is a good thing (both theoretically and practically/genetically/biologically).
> In article <a41c5c09-c8f8-4958-a502-fa99f9051...@m22g2000vbl.googlegroups.com>, > Ed Morton <mortons...@gmail.com> wrote: > ... >>No, that's not how you pass the value of shell variables to an awk >>script. Blah, blah, blah.
> No, that *is* how he passes shell variables to an AWK script. > It also happens to be how I (usually) do it.
And your script would fail if $1 contains spaces. I would hope that you actually do this:
gawk ' BEGIN { RS="---*" } /'"$pattern"'/ ' "$@"
> It may not be how you (Ed) do it, but then again, it takes all kinds to > make a world. Diversity is a good thing (both theoretically and > practically/genetically/biologically).
Indeed.
-- Chris F.A. Johnson, author | <http://cfaj.freeshell.org> Shell Scripting Recipes: | My code in this post, if any, A Problem-Solution Approach | is released under the 2005, Apress | GNU General Public Licence
On Dec 10, 12:31 pm, gaze...@shell.xmission.com (Kenny McCormack) wrote:
> In article <a41c5c09-c8f8-4958-a502-fa99f9051...@m22g2000vbl.googlegroups.com>, > Ed Morton <mortons...@gmail.com> wrote: > ...
> >No, that's not how you pass the value of shell variables to an awk > >script. Blah, blah, blah.
> No, that *is* how he passes shell variables to an AWK script. > It also happens to be how I (usually) do it.
Then you're leaving yourself open to all sorts of nastiness based on possible values of that variable.
> It may not be how you (Ed) do it, but then again, it takes all kinds to > make a world. Diversity is a good thing (both theoretically and > practically/genetically/biologically).
Diversity is a good thing, but if you see someone hitting a nail with the claw side of a hammer, they MIGHT appreciate you suggesting they turn it around rather than quietly applauding their diversity.
> > In article <a41c5c09-c8f8-4958-a502-fa99f9051...@m22g2000vbl.googlegroups.com>, > > Ed Morton <mortons...@gmail.com> wrote: > > ... > >>No, that's not how you pass the value of shell variables to an awk > >>script. Blah, blah, blah.
> > No, that *is* how he passes shell variables to an AWK script. > > It also happens to be how I (usually) do it.
> And your script would fail if $1 contains spaces. I would hope that > you actually do this:
1. Save the lines below to a file call search_script 2. chmod +x search_script 3. Assume that your data is in a file call "data1" 4. Assume that you want to ignore any data prior to the first dash line. If you want to include the data prior to the first dash line in the search, delete the line that set count = -1 5. Issue this command: ./search_script yyy data1 Please let me know if it works for you.
#!/usr/bin/env awk -f
BEGIN { searchPattern = ARGV[1]; # First argument is the search pattern ARGV[1] = ""; # Discard it count = -1; # Skip processing until the first dash line
}
/----/ { # We found the pattern, so print out the information between the # dash lines. if (count > 0 && found) { for (i = 0; i < count; i++) { print buffer[i]; } }
# Reset every time we see the dash line count = 0; found = 0; next;
}
count >= 0 { # Save the lines between the dash lines to the buffer buffer[count++] = $0;
# We found the pattern we want, flag it if (index($0, searchPattern) != 0) found = 1;