Solved

sed insert a string after pattern on same line

Posted on 2013-01-09
3
3,171 Views
Last Modified: 2013-01-09
Trying to use sed.

I can't figure out how to get sed to insert remember=5 after pattern sha512 in /etc/pam.d/system-auth file.

Thanks,

sed -i -e /sha512 / is my pattern and then don't know where to go from there. thanks.

the string in the file appears like this
                                                                             
                                                                               
password          sufficient       pam_unix.so sha512 shadow try_first_pass use_authtok
0
Comment
Question by:atom_jelly
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
Comment Utility
First do not use -i.  Use it when you are happy with the output

sed 's/\(sha512 \)/\1 remember=5/' /etc/pam.d/system-auth

Open in new window


Once it works, use -i option

sed  -i 's/\(sha512 \)/\1 remember=5/' /etc/pam.d/system-auth

Open in new window

0
 

Author Closing Comment

by:atom_jelly
Comment Utility
Thanks, I was not even close to figuring it out but thats what asking and knocking is for.
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
Glad to help :)  Have a nice day!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now