awk script returns a table. need results of 3 rd cell
Using an awk script as below to search through a file,
Code:
awk '/Single-Item/{n++; if (n==3)f=3;} f{print;f--}' Quote:
I am guessing another awk script to iterate through td string would be helpful, but is there any better way to do it? Thanks in advance for reading and giving your valuable time |
What you have is not well-formed XML so most parsers will choke.
But, nonetheless, a parser is what you need for XML (or XHTML as the case may be) unless the input is flawlessly regular. If it is XHTML then you can use one of the many XHTML parsers as they tend to be a bit more tolerant. In that case the xpath you are looking for would be '(//td)[3]' or '//td[3]' My approach would be to whip up a few lines of perl for that using HTML::TreeBuilder::XPath |
Above is the better plan, but if you want to keep what you have, simply look at your math. Currently you are saying once you find the third occurrence, starting printing the next 3 lines.
Just increase 'n' and only print 1 line. If you cannot guarantee the order of the data, then as advised, use a better tool :) |
Thanks for the tips and apologies for a late response. I was able to get the desired output with the following code
Code:
#!/bin/sh |
Not sure if you checked what you have written, but I can guarantee that the code presented will never work.
1. str will equal the string 'awk' and the rest of the line will cause an error 2. Excluding the above error, the awk has no file to read from, so if it did work it would just hang 3. awk has all the power of grep and sed plus more, so not sure why you would use all 3 4. If you have to run an additional grep after all of the previous lines work, you need to rethink your process |
All times are GMT -5. The time now is 10:14 AM. |