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 > 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 07:17 PM
awk: find and replace in certain field only, help needed jkl_jkl Shell Programming and Scripting 5 02-21-2008 10:52 AM
Replace field in csv pcboss Linux 4 01-19-2008 06:24 PM
how to replace field for each record happyv Shell Programming and Scripting 12 06-26-2007 07:56 AM
Replace 10th Field by 2 PradeepRed Shell Programming and Scripting 2 01-19-2006 03:46 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 04-27-2007
munch munch is offline
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!
  #2 (permalink)  
Old 04-27-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
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.
  #3 (permalink)  
Old 04-28-2007
munch munch is offline
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
  #4 (permalink)  
Old 04-28-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

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

Last edited by ghostdog74; 04-28-2007 at 01:42 AM..
  #5 (permalink)  
Old 04-30-2007
munch munch is offline
Registered User
  
 

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

Thanks sooo much! I will be careful!
  #6 (permalink)  
Old 04-30-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
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
  #7 (permalink)  
Old 04-30-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
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
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:15 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