[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

AWK Find and Replace

Posted on 2015-01-19
1
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

649 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