Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run a command like:

watch "ps -ef | grep '^foo.*bar'"

and the matching output line of ps -ef is a long line like

foo <lots and lots of text here> bar

whether this line is output is affected by the terminal size. For example, if the terminal is full screen and this line fits on the screen, then the output will be shown in watch. However, if I resize the window to half the screen size so that the bar is truncated from the screen, then the grep line entirely disappears (presumably the line is truncated before it gets to grep in the pipeline). This is a problem because I'm trying to extract a portion of this line for use later in the pipeline.

Is there any solution to this to prevent the terminal size from affecting the output of grep within a watch command?

share|improve this question
up vote 1 down vote accepted

It's not grep, it's ps. Add the -ww options (ps -efww) to tell it to always output full lines.

share|improve this answer

I don't know what the right solutions is, but this seems to fix the problem,

watch "COLUMNS=160 ps -ef | grep '^foo.*bar'"

at the expense of having the lines from ps folded. Change "160" to be long enough for the longest "foo.*bar" line you expect to see.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .