0

Lets say I have the fallowing cmd:

ls | grep dir

If there are folders which names contains dir then ill see them. If there arent, then I wont see any output at all.

Now, What i want is to see the output of the ls command, and then also see the final output after the grep.

Lets say something like this:

>>ls | grep dir
filea fileb filec
filed dir1  dir2

dir1 
dir2

Where the first 2 rows are the result of ls and the last 2 rows are the result of the grep command.

How do i do that?

MichaelR
  • 969
  • 14
  • 36

3 Answers3

2
ls |tee /dev/tty |grep dir

will do that, although it won't put a space between the two parts.

rojomoke
  • 3,765
  • 2
  • 21
  • 30
0

I'm cheating a bit there, but can't you just do both commands one after another? like (adding an echo to put some space between them):

 ls && echo && ls | grep dir
Arnaud Potier
  • 1,750
  • 16
  • 28
0

The simplest way is to run ls twice:

ls; ls -1 | grep dir

Please pay attention -1 option. grep is line oriented that's why ls should print one dir entry per line.

Győző Papp
  • 148
  • 1
  • 5
  • `-1` is only necessary if the output is a terminal; when writing to a pipe or file, `-1` is effectively implied. – chepner Mar 27 '14 at 16:41