The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace single field out of 60 ajp7701 Shell Programming and Scripting 2 04-21-2008 04:17 PM
awk: find and replace in certain field only, help needed jkl_jkl Shell Programming and Scripting 5 02-21-2008 06:52 AM
Replace field in csv pcboss Linux 4 01-19-2008 02:24 PM
how to replace field for each record happyv Shell Programming and Scripting 12 06-26-2007 04:56 AM
Replace 10th Field by 2 PradeepRed Shell Programming and Scripting 2 01-18-2006 11:46 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-27-2007
Registered User
 

Join Date: Mar 2006
Posts: 5
Replace password field using ed/sed

I need to edit the password file to change the password field to *LK* for a specified account (abctest) like:
abctest:*LK*:135:20::/home/abctest:/sbin/sh

Can anyone help me do this using ed or sed?

Thanks a lot!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-27-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,473
If manipulating the passwd file directly I would suggest you use the safer alternative which is awk.

In this case however, why not just use the system provided command for doing this, usually the passwd or usermod commands have an option for locking accounts.
Reply With Quote
  #3 (permalink)  
Old 04-27-2007
Registered User
 

Join Date: Mar 2006
Posts: 5
I am using the password command for all supported systems except hp10.20 which has no command to lock the password.

How can it be done with awk?

Thanks
Reply With Quote
  #4 (permalink)  
Old 04-27-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,421
Code:
awk -F ":" 'BEGIN{OFS = ":"} /youruser/{$2="*LK*"}{ print}' /etc/passwd
please use at own risk.

Last edited by ghostdog74; 04-27-2007 at 10:42 PM.
Reply With Quote
  #5 (permalink)  
Old 04-30-2007
Registered User
 

Join Date: Mar 2006
Posts: 5
Thumbs up It worked for me

Thanks sooo much! I will be careful!
Reply With Quote
  #6 (permalink)  
Old 04-30-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,473
Quote:
Originally Posted by ghostdog74
Code:
awk -F ":" 'BEGIN{OFS = ":"} /youruser/{$2="*LK*"}{ print}' /etc/passwd
please use at own risk.
Actually you should not use this code, a partial match will result in locking the wrong user.

eg users: user2 and user23 projectuser234 , using user2 will lock all three.

Code:
awk  'BEGIN{IFS = OFS = ":"} $1 == "youruser" { $2 = "*LK*" } { print }' /etc/passwd
Reply With Quote
  #7 (permalink)  
Old 04-30-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,421
Quote:
Originally Posted by reborg
Actually you should not use this code, a partial match will result in locking the wrong user.

eg users: user2 and user23 projectuser234 , using user2 will lock all three.

Code:
awk  'BEGIN{IFS = OFS = ":"} $1 == "youruser" { $2 = "*LK*" } { print }' /etc/passwd
ah yes.. i missed out that one, should be == instead. tks
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:53 PM.


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

Content Relevant URLs by vBSEO 3.2.0