- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: regular expressions
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
тАО09-26-2009 03:14 AM
тАО09-26-2009 03:14 AM
Can somebody help me with a sed and regular expressions?
I need a script that will append 'notsc' to every line in a file that starts with 'kernel' but does not contain 'notsc'.
I tried the following but it doesn't work:
sed -i '/^[[:space:]]*kernel(?!notsc)/s|$| notsc|' grub.conf
Thanks,
Maxim.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2009 12:41 PM
тАО09-26-2009 12:41 PM
Re: regular expressions
First use grep to find out 'kernel' without 'notsc' ;
cat grub.conf | grep -v notsc | grep ^kernel > temp1
sed -e 's/\^kernel/\$notsc/' grub.conf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2009 12:43 PM
тАО09-26-2009 12:43 PM
Re: regular expressions
sed -e 's/\^kernel/\$notsc/g' temp1 > temp2
if it is OK
cat temp2 > grub.conf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2009 01:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2009 04:10 PM
тАО09-26-2009 04:10 PM
Re: regular expressions
# perl -ple 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ xxxxx/' grub.conf
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2009 05:22 PM
тАО09-26-2009 05:22 PM
Re: regular expressions
Hakki - I think that your suggestion will leave only the kernel lines in grub.conf, while I want to leave the file as is, and just to append 'notsc' to some of the lines.
H - I will try you command at work and will let you know whether it works.
James - I asked for a sed command because this script should run on newly installed systems and I am not 100% sure that perl is part of the default installation. But anyway, I will try it at work and will let you know.
Thanks,
Maxim.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 06:49 AM
тАО09-27-2009 06:49 AM
Re: regular expressions
# perl -ple 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ xxxxx/' grub.conf
...should have been:
# perl -ple 's/(^\s*kernel(?!.*notsc))(.*$)/$1$2\ notsc/' grub.conf
The 'xxxxx' was what I used for testing as it simplified spotting good and bad cases.
> "I am not 100% sure that perl is part of the default installation."
Interesting point. If I recall correctly, Perl is part of Debian, Ubuntu, OpenSUSE and definitely Fedora. I'd be very interested to know your findings.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 07:17 AM
тАО09-27-2009 07:17 AM
Re: regular expressions
In our case it's RHEL, but we have a customized installation, so I have to check whether perl is part of this installation.
I will check it on Tuesday, when I'll be in the office and will let you know.
Maxim.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 11:49 PM
тАО09-27-2009 11:49 PM
Re: regular expressions
Here a simple sed script to accomplish this task:
sed -n -e '/notsc/{
p
d
}' -e '/^kernel/s/$/notsc/' -e 'p'
Kind regards,
Kobylka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2009 04:35 AM
тАО09-28-2009 04:35 AM
Re: regular expressions
-May be somebody will come up a solution to make working a string inside a sed ??
test it you will see the problem :
#!/bin/sh
cat testfile > test2file
line2=" notsc"
cat test2file |grep -i kernel |grep -v notsc | while read line
do
sed "s/$line/$line $line2/" test2file > test3file
cp test3file test2file
done