LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   List 4 names from users list and output them to fbusers in numbered ascending order? (http://www.linuxquestions.org/questions/programming-9/list-4-names-from-users-list-and-output-them-to-fbusers-in-numbered-ascending-order-786399/)

fezzie 02-02-2010 05:36 AM

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?

ntubski 02-02-2010 08:33 AM

Quote:

Originally Posted by fezzie (Post 3849378)
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. ;)

fezzie 02-10-2010 11:02 AM

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'?

catkin 02-10-2010 11:08 AM

It would help if you posted the contents of the usernames file.

ntubski 02-10-2010 01:05 PM

Quote:

Originally Posted by fezzie (Post 3859227)
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.


All times are GMT -5. The time now is 09:48 AM.