# Extract data segment using awk??

**URL:** <https://community.unix.com/t/extract-data-segment-using-awk/149555>\
**Category:** Shell Programming and Scripting\
**Created:** [July 26, 2004, 5:07pm UTC](https://community.unix.com/t/extract-data-segment-using-awk/149555 "2004-07-26T17:07:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apalex](https://community.unix.com/letter_avatar/apalex/32/6_449c533f586939b6e5f246632a46421f.png) [@apalex](https://community.unix.com/u/apalex)\
**Post date:** [July 26, 2004, 5:07pm UTC](https://community.unix.com/t/extract-data-segment-using-awk/149555/1 "2004-07-26T17:07:31Z")

</div>

How do I filter a long report, with the "STARTWORD" and "STOPWORD" as the variables to use in my awk command, to print the whole data segment that only contains the matched start/stop word?

awk '/start/, /stop/' file \<- this prints the line, though I need to print the whole segment. Newline separates each data segment.

Thanks and good to be back,

Apalex

---------------  
Report below:  
----------------

Time Stamp line Data1(no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline

Time Stamp line Data2 (no common string)  
NOTNEEDED REPORT.................WORD  
Nextline  
Nextline

Time Stamp line Data3 (no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline

Time Stamp line Data4 (no common string)  
NOTNEEDED REPORT.................WORD  
Nextline  
Nextline

Time Stamp line Data5(no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline

---

<div class="post-metadata">

**Author:** ![Ygor](https://community.unix.com/user_avatar/community.unix.com/ygor/32/104_2.png) [@Ygor](https://community.unix.com/u/Ygor)\
**Post date:** [July 27, 2004, 6:13am UTC](https://community.unix.com/t/extract-data-segment-using-awk/149555/2 "2004-07-27T06:13:37Z")

</div>

I don't think I understand entirely, but you can try this...

```nohighlight
 awk -v RS='' '/START.*STOP/{print $0 "\n"}' file1

```

When RS is null then awk uses blank lines to separate records, so the result is...

Time Stamp line Data1(no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline

Time Stamp line Data3 (no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline

Time Stamp line Data5(no common string)  
STARTWORD.................STOPWORD  
Nextline  
Nextline
