- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: changing a line in multiple .profiles
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
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
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
08-12-2011 11:50 AM
08-12-2011 11:50 AM
Hello I want to make multiple changes of one line in hundreds of .profiles. I do not script well and came up with this.
I want change change a line in .profile that says
A=/1/2/3
to
A=1/4/5/6/3
Will this work?
cd /home
find ./.profile -type f -exec perl -pi'.bak' -e 's/A=\/1\/2\/3/A=\/1\/4\/5\/6\/3' {} \;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 12:28 PM
08-12-2011 12:28 PM
Re: changing a line in multiple .profiles
>I want to make multiple changes of one line in hundreds of .profiles.
If only 100s, there is no need to use find(1).
Assuming your perl syntax is correct:
cd /home
for profile in */.profile; do
perl -pi'.bak' -e 's/A=\/1\/2\/3/A=\/1\/4\/5\/6\/3' $profile
done
I'm not sure if you will have ownership problems after you modify each .profile? I.e. the ownership and permissions may be changed, so you may have to script cloning those.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 01:16 PM - edited 08-12-2011 01:22 PM
08-12-2011 01:16 PM - edited 08-12-2011 01:22 PM
SolutionHi:
Yes, you Perl command will work. You can make it easier to read by writing:
# perl -pi.bak -e 's{A=/1/2/3}{A=1/4/5/6/3}' MYFILE
The idea is to use a different delimiter than a slash since the slash is one of the characters you want to match. The {} ones are nice.
While the permissions of the modified file will be the same as the original, the ownership will be the default for the account running the command.
You can also specify *multiple* files without having to create separate instantiations of a Perl process. Hence, you could do:
# perl -pi.bak -e 's{A=/1/2/3}{A=1/4/5/6/3}' /home/*/.profile
...to do all of them!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 01:48 PM
08-12-2011 01:48 PM
Re: changing a line in multiple .profiles
Thank you James. That worked. I am looking to assign everyone points, but have not figured out how this new forum works yet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 01:54 PM
08-12-2011 01:54 PM
Re: changing a line in multiple .profiles
@John Jimenez wrote:Thank you James. That worked. I am looking to assign everyone points, but have not figured out how this new forum works yet.
There are now kudos in lieu of points. Also, mark the solution that solved the problem. Be aware, though, that marking a particular reply as the one that solved your problem does *not* generate a kudo. Hence, please do both. See:
http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/kudos#kudos
http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/solutions#solutions
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 02:05 PM
08-12-2011 02:05 PM
Re: changing a line in multiple .profiles
hmmmm I wanted to assign more then one kudos, but it only changed the first time I clicked it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2011 02:12 PM
08-12-2011 02:12 PM
Re: changing a line in multiple .profiles
@John Jimenez wrote:hmmmm I wanted to assign more then one kudos, but it only changed the first time I clicked it.
Hi (again):
I'm sorry, you can't do that :-) A kudo is all anyone can give. It has been said that at some point some contributors will be able to give 1+ kudos based on their "rank" in the community. I have no idea of the criteria that might define a higly "ranked" member, either.
I'm happy to have been of help.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2011 12:44 AM - edited 08-13-2011 12:51 AM
08-13-2011 12:44 AM - edited 08-13-2011 12:51 AM
Re: changing a line in multiple .profiles
Update: part of below info was already posted by JRF, but I only noticed after posting, as by some incident, JSF's post didn't show when I replied. Sorry for that. I also wanted to reply to Dennis' post, as his snippet has a syntax error.
Did you know that that s/// allows other delimiters? using / is really awful when changing /'s
cd /home for profile in */.profile; do perl -pi.bak -e's{A=/1/2/3}{A=/1/4/5/6/3}' $profile done
Reads much better, right? Besides that, it also prevents causing syntax errors like Dennis' substitute is missing a trailing /
Another nice thing about using {} pairs, is that you can split over lines. Useful for readability in scripts:
$var =~ s{A=/1/2/3} {A=/1/4/5/6/3};
I hope your code shows in a fixed-width font, otherwise this example is useless.