• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Unix script to parse password file information

I am trying to create a script that will pull information from the comment field in the password file, What I want to do is:
for every entry in "ls /home"  I want to get the first initial and the last name from the First Last name entry in the comment field of the password file. The username would work in most cases but in some cases the username is truncated to 8 char, so for that reason I need to get this information.

 jalberso:x:1002:1000:Jaskson Alberson:/home/jalderso:/usr/bin/bash

so in a case like the above example, I want the output of jalberson
0
aapl
Asked:
aapl
1 Solution
 
psv1973Commented:
try
to get the first initial
cut -f5 -d: /etc/passwd|cut -c 1
to get the lasst name:
cut -f5 -d: /etc/passwd|cut -f2 -d' '

Maybe not the most efficient way of doing this ( you would probably have to use awk or so but it's clear and it'll work
0
 
aaplAuthor Commented:
Yea, that's exactly what I needed, yea the awk portion I already had down, it was the cut that I was stumbling on....


Thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now