1834167 Members
2651 Online
110064 Solutions
New Discussion

About writing the script

 
SOLVED
Go to solution
juno2
Super Advisor

About writing the script

The is a simple question about shell script, please suggest to solve it. thx

i wrote a scrpt :
# process = w |more
#echo $process
the echo result is
userid pts/ ip time process userid pts/ ip time process userid pts/ ip time process userid pts/ ip time process userid pts/ ip time process userid pts/ ip time process ......

how to make the result as the below tidy format ? thx.
userid pts/ ip time process
userid pts/ ip time process
userid pts/ ip time process
userid pts/ ip time process
7 REPLIES 7
Balaji N
Honored Contributor
Solution

Re: About writing the script

hi

what you are doing is assigning a set of values to variable by this command.

w | more generates some output which contains a lot of text and you are assigning this to the variable process. and when you print process, these values get printed.

what are u trying. if you could give some more info, i will be able to help.

correct me if i am wrong.
hth
-balaji

(and juno, you have never assigned points to anybody. pls login and assign points to all your replies. )
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Steve Steel
Honored Contributor

Re: About writing the script

Hi

Since the number of parameters in a line is variable you will not do it.

try something silly like

w|tail -n +3|cut -c1-29,50-256

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Dietmar Konermann
Honored Contributor

Re: About writing the script

Try:
# process=$(w|more)
# echo "$process"

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
juno2
Super Advisor

Re: About writing the script

thx Dietmar Konermann , you method is ok.
Ralph Grothe
Honored Contributor

Re: About writing the script

what purpose does the pipe to more in the command substituion serve?

DUMP=$(w)

should suffice

Madness, thy name is system administration
John Meissner
Esteemed Contributor

Re: About writing the script

process=$(w| awk '{print $1,$2,$3,$4,$5}')
echo $process
All paths lead to destiny
Wilfred Chau_1
Respected Contributor

Re: About writing the script

w | tail -n +3 |awk '{print $1" "$2" "$3" "$NF}' > ~/dummy

cat ~/dummy |while read i j k l
do
echo "$i $j $k $l"
done

rm ~/dummy