LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-02-2010, 05:36 AM   #1
fezzie
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Rep: Reputation: 0
Question List 4 names from users list and output them to fbusers in numbered ascending order?


How would I list 4 users ID numbered 10, 11, 12 and 13 from my users list and output them to a file busers where their names are numbered by ascending order? How would I accomplish that on a one line command?
 
Old 02-02-2010, 08:33 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,494

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Quote:
Originally Posted by fezzie View Post
How would I list 4 users ID numbered 10, 11, 12 and 13 from my users list and output them to a file busers where their names are numbered by ascending order?
Is this homework? Have you tried anything yet?

Quote:
How would I accomplish that on a one line command?
First do it with several lines, then reformat so it's all on one line.
 
Old 02-10-2010, 11:02 AM   #3
fezzie
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Yip correspondence course, so using net for research.
I have done it as follows:
grep [:10-13:] < usernames | tee /usernames2 | sort -g > /badusers
This will list users 10-13, but to list their names would you use 'join'?
 
Old 02-10-2010, 11:08 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
It would help if you posted the contents of the usernames file.
 
Old 02-10-2010, 01:05 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,494

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Quote:
Originally Posted by fezzie View Post
I have done it as follows:
grep [:10-13:] < usernames | tee /usernames2 | sort -g > /badusers
I'm guessing (by the colons) that usernames is in the same format as /etc/passwd:
Code:
username:password:userid:groupid:home:shell
It looks like you are sending output to files in the root directory (/), which is a problem since only the root user will be able to run this.

Quote:
This will list users 10-13,
That grep command will actually list all users; square brackets [] indicate a character class so any line with one of ':','1','0', or '3' will match.

Regular expressions (and therefore grep) don't support numeric ranges.

Quote:
but to list their names would you use 'join'?
You could use cut to extract the username.
 
  


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
How to list the 'chkconfig --list' in alphabetical order? thomas2004ch Linux - Newbie 3 01-08-2010 02:09 AM
List of names xowl General 28 04-10-2007 05:08 PM
How-to list contents of text file in alphabetical order? sucram2g Linux - Software 1 02-19-2007 03:39 AM
Gen Hd List +pkg Order sajjadc Red Hat 0 10-10-2005 02:08 PM
ascending order huno Programming 4 07-22-2005 07:03 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration