Hi everyone,
I'm trying to extract the user name and full name from the finger command without using sed or awk.
Any pointers?
Thanks in advance.
Hi everyone,
I'm trying to extract the user name and full name from the finger command without using sed or awk.
Any pointers?
Thanks in advance.
use perl, use shell script, but can you please post the output of finger ?
It really depends how the system is configured. My version of finger won't display the full name, instead, I have to cat /etc/passwd
my unix is bash based and the finger command output is:
Login Name Tty Idle LoginTime Office
amos.john Amos John pts/26 1 Dec 5 16:18 (77.100.22.07)
What am trying to achieve is extract the Login (amos.john) and Name (Amos John) from this output without using awk or sed.
Any pointers please, thanks.
#!/bin/ksh
echo 'amos.john Amos John pts/26 1 Dec 5 16:18 (77.100.22.07)' | read acct nameF nameL junk
echo "account->[${acct}] FIRSTname->[${nameF}] LASTname->[${nameL}]"
sorry about the double post vgersh99.
the solution you gave didn't work in bash.
I was able to use cut -d ' ' -f1 file to get the first word on the line but cant get the second word on line primarily cos i dont know how to represent the tab delimiter oor multiple space as a delimiter.
the above solution was not a bash solution.
here are a couple of alternatives ( there ARE others as well):
#!/bin/bash
# this one is generic, but uses temp file
finger -sf > /tmp/finger$$
read acct nameF nameL junk < /tmp/finger$$
echo "account->[${acct}] FIRSTname->[${nameF}] LASTname->[${nameL}]"
rm /tmp/finger$$
# this one is bash 2.x++ specific:
a=($(finger -sf))
echo "account->[${a[0]}] FIRSTname->[${a[1]}] LASTname->[${a[2]}]"
sorry for the late feedback.
the suggested solution didn't give me what i wanted which was the first two fields in a finger command i.e. username and full name without using awk or sed.
I found a solution as follows:
username=$(finger | cut -d ' ' -f1) #this gives the username
fullname=$(finger $username | cut -d : -f3) #this gives the fullname
or
fullname=$(grep $username /etc/passwd | cut -d : -f5) #this also gives the fullname