LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Re: Opposite of Cat >>

[ILUG] Re: Opposite of Cat >>

Fergal Daly fergal at esatclear.ie
Sat Jun 15 19:23:43 IST 2002


Here's a solution in a perl one-liner

perl -0 -p -e '@n=/^(\d+),RestartCommand=(?:killall )?ooqstart/gm;$n=join("|", 
@n);s/^($n),.*\n//mg' name_of_file

or you can save this short script as guninstall

#! /bin/bash

perl -0 -p -e '
  BEGIN{$c=shift};                      
  @nums = /^(\d+),RestartCommand=\s*$c\s*$/gm;
  $nums = join("|", @nums);
  s/^($nums),.*\n//mg
' "$@"


and then run

guninstall 'killall ooqstart' config_file > new_config_file
guninstall 'ooqstart .*' new_config_file > newer_config_file

As you can see, this should be able to remove entries one at a time from the 
config file. Just supply it a pattern to look for on the RestartCommand= 
line.

If you're feeling confident, you can replace the -p with -pi and this will 
actually replace the original file, saving you the hassle of creating 
new_config_file and newer_config_file

Eplanation of one-liner:

-p causes Perl to read a file in a line at a time, storing each line in $_
-e causes Perl to execute the piece of Perl for each line then the -p kicks in 
again and prints out whatever is now in $_

-0 changes Perl's causes perl to consider the whole file as a single "line" 
with the result that $_ contains the whole file.

@n=/^(\d+),RestartCommand=(?:killall )?ooqstart/gm;

the m at the end makes sure that the pattern only looks at a line at a time 
and also means that the ^ means the start of a line rather than the start of 
the whole string.

(\d+) will match any sequence of digits and since we're in /g mode, the 
pattern will match repeatedly until the end of the string and these sequences 
of digits will be captured placed in the array @n because they have 
parentheses around them. In the example, these are "99" and "100".

(?:killall )? means that the string "killall " is optional for this pattern to 
match. ie it will match without or without that string. The ?: stops the 
parantheses from capturing anything.

$n=join("|", @n);

join all those numbers together, seaparated by "|"s, giving "99|100"

s/^($n),.*\n//mg

once the $n is replaced, this pattern will look something like

s/^(99|100),.*\n//mg

which says basically nuke any line that starts with "99," or "100,". The "g" 
is important to make sure we don't only nuke the first one. The "m" is needed 
to make ^ mean the start of a line, not the start of the whole string.






More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell