LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 05: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, 06:09 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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, 08:54 PM   #3
amber1
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Original Poster
Blog Entries: 1

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, 10:40 PM   #4
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
how about 'head -n 25' or 'tail -n 25'
 
2 members found this post helpful.
Old 04-19-2013, 11:44 PM   #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, 01:57 PM   #6
amber1
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.
 
  


Reply



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 07:19 AM
LXer: JasperReports 3.6: Creating a Report from XML Data using XPath LXer Syndicated Linux News 0 06-26-2010 10:50 AM
Creating a System and Error Report GreenJelly Linux - Server 0 07-16-2007 09:28 AM
LXer: Creating a Report with JasperReports LXer Syndicated Linux News 0 10-25-2006 05:21 AM
SUSE installer terminated (successfully?) before creating users or root password rose_bud4201 SUSE / openSUSE 2 03-13-2006 03:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:00 AM.

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
Open Source Consulting | Domain Registration