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.

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

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 10-12-2008
c00kie88 c00kie88 is offline
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?
  #2 (permalink)  
Old 10-12-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
awk -F:  '{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp
Is this what you want?
  #3 (permalink)  
Old 10-12-2008
c00kie88 c00kie88 is offline
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:
  #4 (permalink)  
Old 10-12-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
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
  #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,864
how about
Code:
cat /etc/shadow
  #6 (permalink)  
Old 10-12-2008
danmero danmero is offline Forum Advisor  
  
 

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

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
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
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 10:20 PM.


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