Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk and sed help 1

Status
Not open for further replies.
Dec 10, 2003
121
US
I'm using the "finger -s loginid" command on a SUN server to get the last time a user has logged in with their id. I need the first field (userid) and the date field extracted to a file. I have written a script to take the /etc/passwd file and run every userid through the finger -s command. I'm trying to capture only two fields and put a semicolon or something between the two fields into a new file. I am terrible with awk...and sed

Here is one of my records:)
zorman ??? pts/328 <Apr 8, 2003> 192.168.x.x

I would like to collect zorman and the date and put it into a format like so:

zorman;Apr 8, 2003

My goal is to automatically delete userids who have not logged into the system in x amount of time.

Any Ideas?
 
Hi:

There's more than one way of doing this, but I used sed to remove the <> and then used awk to parse & format it:

# all on one line
echo "zorman ??? pts/328 <Apr 8, 2003> 192.168.x.x"|sed -e 's/<//' -e
's/>//'| awk ' { printf("%s; %s %s %s\n", $1, $4, $5, $6) } '

 
Thank You "olded"! I couldn't use the echo because I am fingering the records out of an array variable, but I was able to get this command to work great with my finger command in my ksh script! Thank you so much!!!! [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top