Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Scripting Question
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP