- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: replace data in a stanza
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2008 08:53 AM
тАО05-19-2008 08:53 AM
I want to search a file for a sting then change the last field in the last row of that stanza if it doesn't match a string:
this is how the stanza's look:
usw:
shells = /bin/sh,/bin/bsh,/bin/csh,/bin/ksh
maxlogins = 3000
logintimeout = 60
auth_type = STD_AUTH
next stanza: shells =
maxlogins =
logintimeout =
auth_type = STD_AUTH
in this example when the string usw is matched, check the auth_type and replace STD_AUTH with PAM_AUTH.
I have an idea how to do this by removing the stanza completely and then appending the usw stanza to the bottom of the file and changing STD_AUTH with PAM_AUTH.
I am sure there is a more logical way of doing this?
Thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2008 09:04 AM
тАО05-19-2008 09:04 AM
SolutionI think sed may be an answer.
websitename=bsg21.org
sed s/hpuxconsulting.com/$websitename/g hpuxconsulting.com.virt.conf > $websitename.virt.conf
What this sed sequence does is take a template file hpuxconsulting.com.virt.conf and make a changed copy in this case bsg21.org, the last one I used it on.
It efficiently does a replace and creates a new file with everywhere it sad hpuxconsulting.com now saying bsg21.org
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2008 09:29 AM
тАО05-19-2008 09:29 AM
Re: replace data in a stanza
Treat each stanza as its own record:
# perl -pe '$/="";if (/^usw/) {s/STD_AUTH/PAM_AUTH/}' file
...of course to update in-place:
# perl -pi.old -e '$/="";if (/^usw/) {s/STD_AUTH/PAM_AUTH/}' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2008 09:56 AM
тАО05-19-2008 09:56 AM
Re: replace data in a stanza
Oh, if you prefer 'awk' this works analogously ...
# awk 'BEGIN{RS=""};/^usw/ {sub("STD_AUTH","PAM_AUTH")};{print $0,"\n"}' file
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2008 12:49 AM
тАО05-20-2008 12:49 AM
Re: replace data in a stanza
I have used the awk version however the perl and sed would have done the trick.
Chris
:-)