LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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?

#!/bin/bash

# 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!
Amber
 
Old 04-19-2013, 07:09 PM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Quote:
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,
Code:
grep bash /etc/password | grep home | awk -F: '{print $1}'
cat | grep is sort of "inefficient".
 
Old 04-19-2013, 09:54 PM   #3
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Smile

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
mddnix
Member
 
Registered: Mar 2013
Location: Bengaluru, India
Distribution: Redhat, Arch, Ubuntu
Posts: 498

Rep: Reputation: 137Reputation: 137
how about 'head -n 25' or 'tail -n 25'
 
2 members found this post helpful.
Old 04-20-2013, 12:44 AM   #5
shivaa
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:
Code:
~$ awk 'BEGIN{FS=":"}; /bash/ && /home/ {if(NR<=25) print $1}' /etc/passwd
 
Old 04-22-2013, 02:57 PM   #6
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8
Blog Entries: 1

Original Poster
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.
 
  


Reply


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


All times are GMT -5. The time now is 10:19 PM.

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