# Piping to grep with pbpaste

**URL:** <https://community.unix.com/t/piping-to-grep-with-pbpaste/372130>\
**Category:** macOS\
**Created:** [May 5, 2018, 1:39pm UTC](https://community.unix.com/t/piping-to-grep-with-pbpaste/372130 "2018-05-05T13:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![palex](https://community.unix.com/letter_avatar/palex/32/5_5575768a8748004e209b776fc1b2916d.png) [@palex](https://community.unix.com/u/palex)\
**Post date:** [May 5, 2018, 1:39pm UTC](https://community.unix.com/t/piping-to-grep-with-pbpaste/372130/1 "2018-05-05T13:39:49Z")

</div>

cat file

```nohighlight
1 aaa
2 bbb
3 ccc
4 ddd

```

In TextEdit, I then copy the characters �ccc� to the clipboard. The problem is that the following command gives no output:

```nohighlight
bash-3.2$ pbpaste | grep - file

```

Desired output:

```nohighlight
3 ccc

```

What should the syntax be for that command? I am using MacOS El Capitan with Quartz 2.7.9.

Thanks!

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 5, 2018, 1:56pm UTC](https://community.unix.com/t/piping-to-grep-with-pbpaste/372130/2 "2018-05-05T13:56:56Z")

</div>

Try:

```nohighlight
grep -f <(pbpaste) file

```

or

```nohighlight
grep "$(pbpaste)" file

```

--  
Note: some greps can also do this:

```nohighlight
pbpaste | grep -f - file

```

, but not MacOS' BSD grep.

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [May 5, 2018, 2:00pm UTC](https://community.unix.com/t/piping-to-grep-with-pbpaste/372130/3 "2018-05-05T14:00:19Z")

</div>

Not sure I understand, but if you want the paste board contents piped on stdin to be `grep` ped in `file` , try `grep -f- file`

This should work with simple strings like the one you showed, but be careful if there are characters with special meanings in regexes.

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [May 6, 2018, 2:38pm UTC](https://community.unix.com/t/piping-to-grep-with-pbpaste/372130/4 "2018-05-06T14:38:10Z")

</div>

Note also that on macOS, the `grep` utility only works on complete lines of text. If the text you selected does not include a \<newline\> character at the end of the line you selected, `pbpaste` will only output a partial line of output without a line terminating \<newline\> character.
