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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Print to ps2pdf print queue Sean_69 SUN Solaris 2 10-22-2007 11:00 AM
Print to a ps2pdf print queue. Sean_69 UNIX for Dummies Questions & Answers 1 10-22-2007 10:58 AM
Print Problem in UNIX. Need to know the option to specify the print paper size ukarthik HP-UX 1 06-07-2007 09:35 AM
How do I get awk to print a " in it's print part? LordJezo Shell Programming and Scripting 2 06-27-2006 09:16 PM
cannot print from an application but, i can print from others? 75ping6 UNIX for Dummies Questions & Answers 1 08-02-2004 08:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2008
Registered User
 

Join Date: Apr 2008
Posts: 63
awk - print

Hi all,

I have script below:

#!/bin/sh

$name=blah

awk -F: -v user="$name" '$1 == user{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp

based on above, it will only print one line which is "blah" username details.

What do i need to do to print all contents of shadow file including "modified" blah user?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-12-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 5,214
Code:
awk -F:  '{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp
Is this what you want?
Reply With Quote
  #3 (permalink)  
Old 10-12-2008
Registered User
 

Join Date: Apr 2008
Posts: 63
hi jim,

awk -F: '{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp ---> will show all lines within shadow file but not including the one i has edited.
e.g:
name=blah
awk -F: -v user="$name" '$1 == user{print $1 ":" $2 ":" DUMMY ":" $4}' /etc/shadow > /tmp/shadow.tmp

From the script above, it will only print blah:UMMY: at shadow.tmp
what i need is to print the rest of the users from shadow file including the modified.
e.g:

man:*:13994::::::
nagios:!:13994:0:99999:7:::
named:!:13994:0:99999:7:::
news:*:13994::::::
nobody:*:13994::::::
ntp:!:13994:0:99999:7:::
blah:UMMY:

instead of only blah:UMMY:
Reply With Quote
  #4 (permalink)  
Old 10-12-2008
Moderator
 

Join Date: Feb 2007
Posts: 3,549
Something like this?

Code:
awk -F: -v user="$name" '$1==user{$3="DUMMY"}1' OFS=":" /etc/shadow > /tmp/shadow.tmp
Regards

Last edited by Franklin52; 10-12-2008 at 08:36 AM.. Reason: adding OFS
Reply With Quote
  #5 (permalink)  
Old 10-12-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,770
how about
Code:
cat /etc/shadow
Reply With Quote
  #6 (permalink)  
Old 10-12-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 901
Let's set the OFS
Code:
awk -v user="$name" '{FS=OFS=":"}$1==user{$3="DUMMY"}1'  /etc/shadow > /tmp/shadow.tmp
Reply With Quote
  #7 (permalink)  
Old 10-12-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,453
Quote:
Originally Posted by otheus View Post
how about
Code:
cat /etc/shadow
The above will show the original, not the modified, version of blah
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 07:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66