Print each user at time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print each user at time
# 1  
Old 10-30-2010
Print each user at time

I want to print each user at time and
I wrote :

Code:
cat /etc/passwd | grep "/home" | cut -d: -f > USERS
for USER in  `cat USERS` 
do 
echo "$user"
done

but it didn't work

thanks

Last edited by Scott; 10-30-2010 at 08:35 PM.. Reason: Code tags
# 2  
Old 10-30-2010
Quote:
Originally Posted by testman84
I want to print each user at time and
I wrote :

cat /etc/passwd | grep "/home" | cut -d: -f > USERS
for USER in `cat USERS`
do
echo "$user"
done

but it didn't work

thanks
where is field number Smilie
Code:
cut -d: -f ?

and is there any problem little?
Code:
for USER in `cat USERS`
echo "$user"


Last edited by ygemici; 10-30-2010 at 05:57 PM..
# 3  
Old 10-30-2010
sorry it is
Code:
cat /etc/passwd | grep "/home" | cut -d: -f1 > USERS

I forget to write in the post but i wrote it
but it don't work

Last edited by Scott; 10-30-2010 at 08:35 PM..
# 4  
Old 10-30-2010
Code:
cat /etc/passwd | grep "/home" | cut -d: -f1 > USERS
for user in `cat USERS`
 do
  echo "$user"
 done

Code:
for user in `grep "/home" /etc/passwd |cut -d: -f1`
 do
   echo "$user"
 done

This User Gave Thanks to ygemici For This Post:
# 5  
Old 10-30-2010
Quote:
Originally Posted by testman84
I want to print each user at time and
I wrote :

cat /etc/passwd | grep "/home" | cut -d: -f > USERS
for USER in `cat USERS`
do
echo "$user"
done

but it didn't work

thanks
Useless use of cat here: cat /etc/passwd | grep "/home"
Code:
grep "/home" /etc/passwd

does the same.

As ygemic mentioned, have a look at the variable names in your for statement. You echoing an empty variable.

I don't know why you redirect the output to a file
Code:
grep "/home" /etc/passwd | cut -d: -f1

does what you want.
This User Gave Thanks to pharyx For This Post:
# 6  
Old 10-30-2010
thanks it works
# 7  
Old 10-30-2010
all in one.

Code:
awk -F":" '/\/home/{print $1}' /etc/passwd

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transpose Datefield from rows to column + Print time diff

Hi Experts, Can you please help me in transposing Datefield from rows to column and calculate the time difference for each of the Jobids: Input File: 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012 12:36:26,JOB_5350 Required Output:... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

2. Shell Programming and Scripting

Compare two timestamps and print elapsed time

Hi, I am unable to Difference between two time stamps in Linux and display the total elapsed time . Source date: Aug 15, 2012 02:00:03 Target date: Aug 14, 2012 18:00:03 # based on the forums I am using the below function. Converted dates into this format Src_dt=20120814180003... (7 Replies)
Discussion started by: onesuri
7 Replies

3. Shell Programming and Scripting

what would a script include to find CPU's %system time high and user time high?

Hi , I am trying to :wall: my head while scripting ..I am really new to this stuff , never did it before :( . how to find cpu's system high time and user time high in a script?? thanks , help would be appreciated ! :) (9 Replies)
Discussion started by: sushwey
9 Replies

4. UNIX for Advanced & Expert Users

Print particular time upto the next occurance

Hi Guys, I am having some issue in one aspect. I am having data like - 00:00 X-1 Y-1 Z-4 A-5 E-6 . . . . 01:00 Z-9 X-1 Z-5 A-8 E-7 (2 Replies)
Discussion started by: aniketdixit
2 Replies

5. UNIX for Advanced & Expert Users

time duration of being online of a particular user given the user name

in a multi user system of 3 users X,Y,Z, if i know that X is presently online, is it possible to determine for how long has he been online? i mean the time duration (3 Replies)
Discussion started by: arindamlive
3 Replies

6. Shell Programming and Scripting

awk print specific columns one row at a time

Hello, I have the following piece of code: roleName =`cat $inputFile | awk -F';' '{ print $1 }'` roleDescription =`cat $inputFile | awk -F';' '{ print $2 }'` roleAuthProfile =`cat $inputFile | awk -F';' '{ print $3 }'` mappedUserID (5 Replies)
Discussion started by: pr0tocoldan
5 Replies

7. UNIX for Dummies Questions & Answers

Print user password

Hi everyone. I have root acces to an Ubuntu machine. This machine have several users so, being root, I can access to their account without knowing their password, simply usingsudo su userBut I need to know the password of a specific user, so in this situation, is there a technique to know what is... (3 Replies)
Discussion started by: canduc17
3 Replies

8. AIX

Time Zone for a User Different From Server Time

Hi, A server runs on EDT. Can I set a user with time-zone GMT without changing the server time? regards, Roshni (1 Reply)
Discussion started by: RoshniMehta
1 Replies

9. Shell Programming and Scripting

awk to print files in a dir between the given time stamp

hi all, i want to print all the files in a directory. between a time stamp like $8>=07:00 and $8<=09:00. please give me commands not only in awk by any other commands also. Thanks. (3 Replies)
Discussion started by: Arunprasad
3 Replies

10. Shell Programming and Scripting

how to print the date and time separately???

HI, I have a script where the date and time has to e printed separately as below date = "Wed Jan 16 2008" time = "14:17:57 IST" using date command gives me tho out put Wed Jan 16 14:17:57 IST 2008 i need only Wed Jan 16 2008 and 14:17:57 IST both stored in two different variables.... (8 Replies)
Discussion started by: jisha
8 Replies
Login or Register to Ask a Question