Display sorted list using sed command

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Display sorted list using sed command
# 1  
Old 04-02-2013
Display sorted list using sed command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Write a command line that will display a sorted list of logged in users. Just display the username and no other information. To accomplish this task you must use the sed command (The cut command is not allowed).


2. Relevant commands, code, scripts, algorithms:
Must use the sed command.


3. The attempts at a solution (include all code and scripts):
I am not sure how to even go about this question. Still really new at shell scripting.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Calvin College, Grand Rapids MI, USA, Johnson, CO 142

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 04-02-2013
Share your thoughts on solving this question? Show us what have you tried so far?
This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-02-2013
Quote:
Originally Posted by Yoda
Share your thoughts on solving this question? Show us what have you tried so far?
For starters I have been just trying to figure out the formatting of using the sed command with the who command. I have been trying w | sed and I am getting a weird result. Im guessing im barking up the wrong tree by trying to pipe w with sed. I was not able to find any similar examples in our book "Unix Shell Programing".

---------- Post updated at 12:20 PM ---------- Previous update was at 12:11 PM ----------

Quote:
Originally Posted by Yoda
Share your thoughts on solving this question? Show us what have you tried so far?
would it make a difference if i used sed | who ?
# 4  
Old 04-02-2013
I would recommend to use who instead of w because then you don't have to worry about skipping the header lines that is present in w output.

You have to pipe who output to sed, use regular expression to remove every character followed by first field (use blank space as delimiter).

Finally pipe the result to sort command to get a sorted list.

Something like:
Code:
who | sed your_regexp_here | sort

These 2 Users Gave Thanks to Yoda For This Post:
# 5  
Old 04-02-2013
Quote:
Originally Posted by Yoda
I would recommend to use who instead of w because then you don't have to worry about skipping the header lines that is present in w output.

You have to pipe who output to sed, use regular expression to remove every character followed by first field (use blank space as delimiter).

Finally pipe the result to sort command to get a sorted list.

Something like:
Code:
who | sed your_regexp_here | sort

Wow, thank you so much for the help. That really clears some things up for me. I really appreciate it.

---------- Post updated at 10:01 PM ---------- Previous update was at 01:37 PM ----------

so this was what my answer was.

[kofine05 ~]$ who | sed 's/ .*$//' | sort
anthonyl
darnella
kevinbis
robertom
root
[kofine05 ~]$

does that make sense?
# 6  
Old 04-02-2013
Yes it does make sense. Good work!

By the way if there are multiple sessions from same user, you can use sort to get rid of duplicates. Check the sort man pages to understand how to get unique values.
Code:
man sort

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Display SAM user list at the command line

Hello, I've been doing Linux and AIX administration for years, but I'm very new to HPUX. We have an old audit process which involves someone manually using sam to generate user lists. I'd like to kill that old process with fire... But... After working a bit in the morning to try and pull... (3 Replies)
Discussion started by: Celt1977
3 Replies

2. UNIX for Beginners Questions & Answers

UNIX command to display Owner,Group,Root and Subdirectories list

Hi Team, Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path. I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this . Here is the sample result... (6 Replies)
Discussion started by: vasuvv
6 Replies

3. Shell Programming and Scripting

Inserting lines from one file to a sorted list

Hello friends! I am working a Psychology/Neuro* project where I am sorting inline citations by category. The final step of the process has me a little stuck. I need to take citations from a text list and sort them in another text file. Here is a file X example... (1 Reply)
Discussion started by: danbroz
1 Replies

4. Shell Programming and Scripting

Display date in mm/dd/yy format in sed command

Hi All, Following is my issue. $MAIL_DOC = test.txt test.txt contains the following text . This process was executed in the %INSTANCE% instance on %RUNDATE%. I am trying to execute the following script var=`echo $ORACLE_SID | tr ` NOW=$(date +"%D") sed -e... (3 Replies)
Discussion started by: megha2525
3 Replies

5. Shell Programming and Scripting

Match and insert in a sorted list

I have a sorted list (python) and I want to insert a string if it matches the pattern in list. Example : Sorted List Above list is in sorted order. I need to insert a name in sorted order and also if the name already exist then it should be inserted before the existing... (1 Reply)
Discussion started by: pratapsingh
1 Replies

6. Shell Programming and Scripting

using sed command to display contents where line numbers are stored in variables

if i want to display the contents of a file between say line number 3 and 10 then i use the following command sed -n '3,10p' filename if this 3 was contained in x and 10 was contained in y then how wud this command modified? sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Discussion started by: arindamlive
2 Replies

7. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

8. Shell Programming and Scripting

Sorted list by time of spu processing

Hi, i have to make a command in unix system which make a sorted list by cpu time (not %cpu ). If the application exists more than a time I would like to keep only one copy. Could you help me please ??? P.s : I am trying --> ps aux --sort -%cpu | uniq but I understand that is wrong (5 Replies)
Discussion started by: petros55
5 Replies

9. UNIX for Dummies Questions & Answers

Need to display sorted output on 1 line!

#!/bin/bash { && ; } || { echo "Must enter between 1 and 5 parameters" exit 1 } for P do echo $P >> /tmp/task3 done echo "SORTED: $(sort -n -r /tmp/task3)" rm -f /tmp/task3 (2 Replies)
Discussion started by: knc9233
2 Replies

10. Shell Programming and Scripting

Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd. I've tried awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq This list whoever does... (7 Replies)
Discussion started by: kungfuice
7 Replies
Login or Register to Ask a Question