Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-19-2013, 06:30 PM   #1
LQ Newbie
Registered: Mar 2013
Posts: 8
Blog Entries: 1

Rep: Reputation: Disabled
Smile creating a report of users using /etc/password?


I need to write a script that creates a report using 25 users accounts from /etc/passwd;

I wrote the following script but it is creating a report of all the users, I just need 25 would anybody be able to help me please?


# Grab a list of users from the /etc/passwd file

cat /etc/passwd |grep bash |grep home | awk -F: '{print $1}'

Thank you in advance!
Old 04-19-2013, 07:09 PM   #2
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Originally Posted by amber1 View Post
cat /etc/passwd |grep bash |grep home | awk -F: '{print $1}'
Amber, I don't have an answer for you, but I have some advice,
grep bash /etc/password | grep home | awk -F: '{print $1}'
cat | grep is sort of "inefficient".
Old 04-19-2013, 09:54 PM   #3
LQ Newbie
Registered: Mar 2013
Posts: 8

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled

Hi Habitual,

I appreciate your help but your command is doing the exact same as mine, it is making a report of all users instead of just 25.
Old 04-19-2013, 11:40 PM   #4
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 540

Rep: Reputation: 153Reputation: 153
how about 'head -n 25' or 'tail -n 25'
2 members found this post helpful.
Old 04-20-2013, 12:44 AM   #5
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Simply awk can do it, as:
~$ awk 'BEGIN{FS=":"}; /bash/ && /home/ {if(NR<=25) print $1}' /etc/passwd
Old 04-22-2013, 02:57 PM   #6
LQ Newbie
Registered: Mar 2013
Posts: 8

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thnx to all for your help I appreciate it. At the end the 'tail -n' command helped me posted by mddesai, thanks for your help sir.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
need a shell script for creating report HariharanV Linux - Software 1 08-31-2010 08:19 AM
LXer: JasperReports 3.6: Creating a Report from XML Data using XPath LXer Syndicated Linux News 0 06-26-2010 11:50 AM
Creating a System and Error Report GreenJelly Linux - Server 0 07-16-2007 10:28 AM
LXer: Creating a Report with JasperReports LXer Syndicated Linux News 0 10-25-2006 06:21 AM
SUSE installer terminated (successfully?) before creating users or root password rose_bud4201 SUSE / openSUSE 2 03-13-2006 04:44 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration