- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Scripting Question
Operating System - Linux
1752805
Members
5622
Online
108789
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО09-20-2004 10:25 PM
тАО09-20-2004 10:25 PM
Hello all (again, I swear I post more than anyone else on here!),
We're using SuSE here and the installation can be a little manual at time. Now most installs we use a Ghost image - so that's easy, but there are a couple of custom installs where we can't use Ghost and need to make lots of manual modifications to files that I'd like to automate.
Now, consider the /etc/profile file as a good example. My default one has the line:
test -z "$MAIL" && MAIL=/var/spool/mail/$USER
But I'd like that just to be (for backward compatibility in users' profiles):
MAIL=/var/spool/mail/$USER
Now I could achieve this in a script by:
sed -e 's/test -z "$MAIL" && MAIL=\/var\/spool\/mail\/$USER/MAIL=\/var\/spool\/mail\/$USER/' /etc/profile > /tmp/profile2; mv /tmp/profile2 /etc/profile
Which is a bit messy, and if I have multiple lines to modify in the file, then I'm going to a lot of file copying.
Can anyone suggest a simpler method to automate this? It would be nice if the file could be modified directly rather than having to use redirects...
Any ideas chaps?
Mike
We're using SuSE here and the installation can be a little manual at time. Now most installs we use a Ghost image - so that's easy, but there are a couple of custom installs where we can't use Ghost and need to make lots of manual modifications to files that I'd like to automate.
Now, consider the /etc/profile file as a good example. My default one has the line:
test -z "$MAIL" && MAIL=/var/spool/mail/$USER
But I'd like that just to be (for backward compatibility in users' profiles):
MAIL=/var/spool/mail/$USER
Now I could achieve this in a script by:
sed -e 's/test -z "$MAIL" && MAIL=\/var\/spool\/mail\/$USER/MAIL=\/var\/spool\/mail\/$USER/' /etc/profile > /tmp/profile2; mv /tmp/profile2 /etc/profile
Which is a bit messy, and if I have multiple lines to modify in the file, then I'm going to a lot of file copying.
Can anyone suggest a simpler method to automate this? It would be nice if the file could be modified directly rather than having to use redirects...
Any ideas chaps?
Mike
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2004 12:18 AM
тАО09-21-2004 12:18 AM
Solution
perl -p -i.bak -w -e 's/change/replaced/g' filename
will replace each "change" string with "replaced" in file named "filename" and it will create a backup "filename.bak" in case something went wrong.
-p option tells perl to write a program
-i.bak stands for extension of a backup
-w turns on warnings
-e says that executable code follows.
will replace each "change" string with "replaced" in file named "filename" and it will create a backup "filename.bak" in case something went wrong.
-p option tells perl to write a program
-i.bak stands for extension of a backup
-w turns on warnings
-e says that executable code follows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-21-2004 01:27 AM
тАО09-21-2004 01:27 AM
Re: Scripting Question
My good man that's exactly what I'm looking for!
Works a treat!
Works a treat!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP