Solved

AWK Find and Replace

Posted on 2015-01-19
1
259 Views
Last Modified: 2015-01-19
I am new in awk and i want to replace a whole line. Its a part of the hardening script.

in /etc/pam.d/system-auth i need to change some configurations entry:

so there is a line called password requisite pam_cracklib.so

and it needed to change to password required pam_cracklib.so ...

So i thought i try to find first if there is already the line password required before i replace it, but i can not find the right way.

How is this been done, maybe on a different way???
0
Comment
Question by:Wilder_Admin
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40557591
You should use "sed" instead of "awk". As opposed to "awk" GNU "sed" on Linux can change the content of files "in place" (sort of).

sed -i.bak 's/password requisite pam_cracklib.so/password required pam_cracklib.so/' /etc/pam.d/system-auth

The flag "-i.bak" will instruct "sed" to create an unchanged backup file "system-auth.bak" before making the actual changes.

There is no need to check if the desired string is already present - if the "old" string is not there nothing will be changed.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 36
Intranet and Kerberos Authentication (not sharepoint!) 8 95
unix example issues 18 49
AWS CLI issues with Tags 3 31
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
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.

762 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

19 Experts available now in Live!

Get 1:1 Help Now