LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   AWK- processing data inside start/stop pairs but ignoring start/stop lines (http://www.linuxquestions.org/questions/programming-9/awk-processing-data-inside-start-stop-pairs-but-ignoring-start-stop-lines-676453/)

cliffoij 10-15-2008 04:42 AM

AWK- processing data inside start/stop pairs but ignoring start/stop lines
 
Hi all

I would like to know how to perform a small task in AWK. I'm able to extract data from a text file using "awk '/start/,/stop/'" all fine - I now wish to process the data further from the extract using AWK but ignoring the start/stop pair used to define the data set.

.
Start of text
line1 word1 word2
line2 word1 word2
End of Text

Is this possible please - any ideas ? Using the start/stop pair thereby inclus the first and last lines in the output, which I don't wish to process.

Cheers - Ian

burschik 10-15-2008 06:08 AM

You can check whether the line matches the start or stop pattern. If so, do nothing. Else continue with whatever you need to do.

Code:

awk '/b/, /d/ {if ($0 ~ /b/ || $0 ~ /d/) {} else {print;}}'

theYinYeti 10-15-2008 06:17 AM

Something like that maybe:
Code:

awk '
/Start of text/ {
  process="true"
  next
}
/End of text/ {
  process=""
  next
}
process=="true" {
  ...do what you have to do...
}'

Yves.


All times are GMT -5. The time now is 08:11 PM.