The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting specific info from finger command franny UNIX for Dummies Questions & Answers 1 12-05-2007 01:13 PM
How to unset 'finger' info? Chanakya.m Shell Programming and Scripting 3 01-23-2006 09:12 AM
Extracting Info muneebr UNIX for Dummies Questions & Answers 3 09-06-2005 08:57 AM
extracting info from Unix database to construct a visual diagram fusion99 UNIX for Advanced & Expert Users 0 11-30-2004 01:29 AM
How to find out the spec of my AIX? E-Quality UNIX for Dummies Questions & Answers 2 09-18-2001 09:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-05-2007
franny franny is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 5
Extracting spec info from finger.

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.
  #2 (permalink)  
Old 12-05-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
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
  #3 (permalink)  
Old 12-05-2007
franny franny is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 5
Extracting specific info from finger command

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.
  #4 (permalink)  
Old 12-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
#!/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}]"

  #5 (permalink)  
Old 12-05-2007
franny franny is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 5
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.
  #6 (permalink)  
Old 12-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
the above solution was not a bash solution.
here are a couple of alternatives ( there ARE others as well):

Code:
#!/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]}]"

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0