The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-21-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
Lightbulb Is awk vs cut which one is better

i was trying to work on program to look for users never log on sever.. using awk
with awk is working
last| awk '{print $1}' |sort -u > /tmp/users1$$
cat /etc/passwd | awk -F: '{print $1}' |sort -u > /tmp/users2$$
comm -13 /tmp/users[12]$$
rm -f /tmp/users[12]$$

with cut it is not working

last| cut -c1-10 |sort -u > /tmp/users1$$
cat /etc/passwd |cut -d':' -f1 | sort -u > /tmp/users2$$
comm -13 /tmp/users[12]$$
rm -f /tmp/users[12]$$

i have another idea by using for loop and count number users repeated. if anyone has better idea to solve this problem please help.
Reply With Quote
Forum Sponsor
  #2  
Old 11-21-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
It isn't working because with cut, you are cutting the first 10 columns. This causes spaces to be padded to the actual usernames in the /tmp/users1$$ file.

Use this instead:

last| cut -d" " -f1 |sort -u > /tmp/users1$$
Reply With Quote
  #3  
Old 11-22-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
thanks

it worked ..thanks
but is there any other way by not using comm and diff to compare 2 files ..
Reply With Quote
  #4  
Old 11-22-2007
Registered User
 

Join Date: Oct 2007
Posts: 155
I love one-line commands.

Code:
(last | awk '{print$1}'; awk -F: '{print$1}' /etc/passwd) | sort | uniq -u
The command "uniq -u" show only unrepeated lines, which would be "users in passwd but NOT in wtmp".
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0