how to find perticular column in linux using

February 11, 2011 at 22:32:38
Specs: LInux
in linux first i type who command to see that howmany student use this computer,,,
in this i have to find perticular column ...
for example ID or date....
so what to do or how i do this using cut command
please give answer.....

See More: how to find perticular column in linux using

Report •

#1
February 12, 2011 at 21:26:07
The cut command is not the best tool for this problem. awk is or maybe a pure shell solution is such as this:

#!/bin/bash

who|while read col1 col2 col3 col4 col5
do
   # print the date
   echo "$col3"
done

Anyway, getting back to cut: Are you asking for a cut solution because this is home work? If so, I won't give you the entire solution but I'll show you what the problem is with using cut. Here is the output of the who command on my Unbuntu system:

nails      pts/0        2011-02-12 21:00 (:0.0)

the problem is that cut sees a field delimiter as only one space. In order for the output of the who command to have the 3rd field as the date, there can only be 1 space between columns:

nails pts/0 2011-02-12 21:00 (:0.0)

Pipe the output of the who cammand to the translate command to remove the excess spaces:

who|tr -s [:space:]

I will leave the rest of the solution to you.

You can pipe the above command to the cut command to get the proper column. HINT: look at the man page for cut's -d and -f options.



Report •
Related Solutions


Ask Question