The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2007
macrules macrules is offline
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.
  #2 (permalink)  
Old 11-21-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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$$
  #3 (permalink)  
Old 11-22-2007
macrules macrules is offline
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 ..
  #4 (permalink)  
Old 11-22-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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".
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0