- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- regular expressions
Operating System - Linux
1755645
Members
3353
Online
108837
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-29-2009 10:06 PM
тАО09-29-2009 10:06 PM
Re: regular expressions
Thank you everybody for all the suggestions.
Hakki - you script might do the job, but I am looking for a more "elegant" solution. Thank you for the effort anyway.
Kobylka - your script doesn't seem to work.
James - your perl suggestion does the job, but it prints the contents to standard output rather than replacing the actual file. It's probably easy to change it to replace the file, but I am not a big perl expert. BTW, our default RHEL installation does include perl.
And the winner is H.Becker. This is exactly what I need. Here is the exact command that I am going to use:
sed -i '/^[[:space:]]*kernel.*notsc.*/ !{s/^[[:space:]]*kernel.*/& notsc/}' grub.conf
Have a great day,
Maxim.
Hakki - you script might do the job, but I am looking for a more "elegant" solution. Thank you for the effort anyway.
Kobylka - your script doesn't seem to work.
James - your perl suggestion does the job, but it prints the contents to standard output rather than replacing the actual file. It's probably easy to change it to replace the file, but I am not a big perl expert. BTW, our default RHEL installation does include perl.
And the winner is H.Becker. This is exactly what I need. Here is the exact command that I am going to use:
sed -i '/^[[:space:]]*kernel.*notsc.*/ !{s/^[[:space:]]*kernel.*/& notsc/}' grub.conf
Have a great day,
Maxim.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2009 03:49 AM
тАО09-30-2009 03:49 AM
Re: regular expressions
Hi Maxim:
> James - your perl suggestion does the job, but it prints the contents to standard output rather than replacing the actual file
That's easy to make happen. We simply add the '-i' switch to enable in-place editing and optionally an argument with it to use as a suffix for a backup copy of the unmodified file. In all:
# perl -ple 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ notsc/' grub.conf
...becomes:
# perl -pi.old -e 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ notsc/' grub.conf
The 'grub.conf' will be modified in situ while the unmodified file will be present as 'grub.conf.old'.
Regards!
...JRF...
> James - your perl suggestion does the job, but it prints the contents to standard output rather than replacing the actual file
That's easy to make happen. We simply add the '-i' switch to enable in-place editing and optionally an argument with it to use as a suffix for a backup copy of the unmodified file. In all:
# perl -ple 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ notsc/' grub.conf
...becomes:
# perl -pi.old -e 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ notsc/' grub.conf
The 'grub.conf' will be modified in situ while the unmodified file will be present as 'grub.conf.old'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2009 05:27 AM
тАО09-30-2009 05:27 AM
Re: regular expressions
Thanks for the update James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2009 10:20 PM
тАО11-16-2009 10:20 PM
Re: regular expressions
>Kobylka - your script doesn't seem to work.
It seems to work fine for me. If you provide a file, it writes the output to stdout. Though -i option doesn't work with -n.
It seems to work fine for me. If you provide a file, it writes the output to stdout. Though -i option doesn't work with -n.
- « Previous
-
- 1
- 2
- Next »
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