1830899 Members
2897 Online
110017 Solutions
New Discussion

script pid

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

script pid

If my file looks like this:

1506
/usr/lib/sendmail -bd -q15m

how can I strip out the second line?
All I want is the pid number?

10x RPM...
UNIX IS GOOD
4 REPLIES 4
Sundar_7
Honored Contributor
Solution

Re: script pid

awk 'NR==1 {print}' /tmp/infile

head -1 /tmp/infile

Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: script pid

Actually, if all you want to do is read one line of a file then simply read it. The shell's read command will read one line of a file and no external command like awk is required.

read PID < myfile
echo "Pid = \"${PID}\"."
If it ain't broke, I can fix that.
Ivan Ferreira
Honored Contributor

Re: script pid

Lines that contains only numbers:


grep -E "^[0-9]*$" filename

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
James R. Ferguson
Acclaimed Contributor

Re: script pid

Hi:

More than one way, sure:

# sed -n '1p' file

...prints only the first line.

Regards!

...JRF...