# Issues while pattern matching using grep

**URL:** <https://community.unix.com/t/issues-while-pattern-matching-using-grep/319558>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [November 7, 2012, 11:52pm UTC](https://community.unix.com/t/issues-while-pattern-matching-using-grep/319558 "2012-11-07T23:52:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RP09](https://community.unix.com/letter_avatar/rp09/32/6_22734026db12803ebb3e059622ac3534.png) [@RP09](https://community.unix.com/u/RP09)\
**Post date:** [November 7, 2012, 11:52pm UTC](https://community.unix.com/t/issues-while-pattern-matching-using-grep/319558/1 "2012-11-07T23:52:10Z")

</div>

Hi,

I have a file f1 wi the following data

# f1.txt

Report ID  
Report Name  
-----------------------------------------------------------------

```
      Post Requests : 2 Post successes : 2

```

=============================================

I need to search for the word "Post" and copy them in a different file with the out put as below:

# output.txt should be

Post Requests:2  
Post successes:2

Please help me on this!

---

<div class="post-metadata">

**Author:** ![guruprasadpr](https://community.unix.com/user_avatar/community.unix.com/guruprasadpr/32/1542_2.png) [@guruprasadpr](https://community.unix.com/u/guruprasadpr)\
**Post date:** [November 8, 2012, 12:20am UTC](https://community.unix.com/t/issues-while-pattern-matching-using-grep/319558/2 "2012-11-08T00:20:51Z")

</div>

Hi

```nohighlight
$ sed -n '/Post /s/Post s/\n&/p' file
Post Requests : 2
Post successes : 2

```

Guru.

---

<div class="post-metadata">

**Author:** ![senthilkumark](https://community.unix.com/letter_avatar/senthilkumark/32/6_22734026db12803ebb3e059622ac3534.png) [@senthilkumark](https://community.unix.com/u/senthilkumark)\
**Post date:** [November 8, 2012, 1:34am UTC](https://community.unix.com/t/issues-while-pattern-matching-using-grep/319558/3 "2012-11-08T01:34:10Z")

</div>

Try this one also

```nohighlight
awk '/Post/{gsub(/Post/,"\nPost");sub(/^\n/,"");print;}' f1

```

Thank you,  
Senthil
