V
V
Valery Ivanov2015-01-04 16:57:35
bash
Valery Ivanov, 2015-01-04 16:57:35

How to write a command to a file?

There is such a command:
ps -U user | grep program | grep -v grep | awk '{print $1}'
If executed, it will return the PID of program.
How can I write this PID to a file without outputting an extra line? Just numbers without a newline
If you just add >, it will come out like this:
3acb31cdc1394313a0d45e207c96cc04.PNG
But I don't want the second line to appear

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Grigoriev, 2015-01-04
@valeragan

ps -U user | grep program | grep -v grep | awk '{print $1}' | grep -v '^$' > pid.out

Z
Zr, 2015-01-05
@Zr

> ps -U user | grep program | grep -v grep | awk '{print $1}'

Terrible. You definitely procps-ngdon’t have it installed there, otherwise:
$ pgrep -U user program > program.pid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question