Solved

replace text

Posted on 2004-04-11
11
513 Views
Last Modified: 2013-12-26
The below command would replace pwdwarntime = 0 to  pwdwarntime = 14
cat /etc/security/user | sed "127,200s/pwdwarntime = 0/pwdwarntime = 14/"

But I require to replace pwdwarntime = XX to pwdwarntime = 14

XX mean any value.

Thanks in advance
0
Comment
Question by:madan1278
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 90 total points
ID: 10800860
sed "127,200s/pwdwarntime = .*/pwdwarntime = 14/"
0
 
LVL 2

Author Comment

by:madan1278
ID: 10803584
Thankyou very much.
I have another question for which I have increased the points further up by 75

cat passwd

root:
     password = gCwSI.DOGx7Jg
     some text here

daemon:
      password = jsfdsf.24343444
      some text here

madan:
        password = 1V5dvL8cAjTSk
        some text here

I need to change password = * only for the ID daemon. Is it possible.

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 10803944
I hope you're not posting real passwords in a public forum
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:madan1278
ID: 10804415
its just a test machine. shdnt be  a problem.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10809402
Why are you updating the passwords manually?
0
 
LVL 3

Accepted Solution

by:
dtkerns earned 60 total points
ID: 10809687
this is quite hardcoded, but it meets your stated requirements:

nawk 'NF == 0 { this = 0}
$1 == "daemon:" { this = 1 }
this == 1 && $1 == "password" { line = $0 ; sub($3, "*", line); print line; next }
        { print }' passwd > newpasswd

mv newpasswd passwd # trust me?

you could just use:
this == 1 && $1 == "password" {  $3 = "*" }
instead of that complex line, but that looses white space at the start of the line

I've also not seen a password file in that format, but who am I to judge! ;)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10809779
This is AIX's format.  Naturally, they do everything a little bit different.  I'd still like to know what madan1278 is *really* trying to do.  This sledgehammer approach can't be the best way.  It's always dangerous to manually manipulate passwords.
0
 
LVL 3

Expert Comment

by:dtkerns
ID: 10809928
well, I wont claim any expertise in AIX, but I jumped on one:

# uname -a
AIX <edited to save my job> 3 4 000179194C00

# head -1 /etc/passwd
root:!:0:0::/:/bin/ksh

looks "normal" to me. maybe 3.4 is an old version, and IBM has "improved" it! lol
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10809963
/etc/passwd is pretty much the same, but AIX uses a whole series of files under /etc/security to hold the shadow information, plus a whole lot more.
0
 
LVL 3

Expert Comment

by:dtkerns
ID: 10809997
ah, thanks. ... thus your concern on manual edits, it's all making sense! :)
0
 
LVL 2

Author Comment

by:madan1278
ID: 10831904
LINE=`grep -nw "${user}:" /etc/security/passwd| awk -F: '{print $1}'`
PASS=`expr $LINE + 1`
cat /etc/security/passwd | sed "${PASS}s/password = .*/password = */" > /tmp/passwd
mv /tmp/passwd /etc/security/passwd

I follwed the above method. But the comments from dtkerns were useful. As said I will split my points to ozo & dtkerns

Thanks for all ur help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 189
conditional code and condition difference 9 84
sum28 challenge 31 115
FizzBuzz challenge 9 82
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question