Hello monks,
I have the following script where I want replace a line in my groups file with a new line containing new group members.
Here is my code:
#!/usr/bin/perl -w
use strict;
my $group = "sbo";
my $newstring = "sbo::18659:x0929,x1465,x1368,x5552;
my $backup = "/etc/group";
my $new = "/etc/group.tmp";
#back up group
`cp -f $backup $backup.4623`;
#fix group
open (GROUP, "<", $backup);
open (NEW, ">", $new);
while (<GROUP>){
s/^$group/$newstring/;
print NEW $_;
}
close GROUP;
close NEW;
print "\n";
print "\n";
system("cat $backup |grep $group");
#system("ls -lad $dirs");
print "\n";
system("hostname");
print "\n";
Here is the original string and the output data. As you can see the output substitutes the string but then adds the :: and everything after it again. I haven't been able to figure out how to escape the :: to make it quit doing this. Please shed some light.
_DATA_
diff /etc/group /etc/group.tmp
104c104
< sbo::18659:x0929,x1465
---
> sbo::18659:x0929,x1465,x1368,x5552::18659:x0929,v1x1465,x1368,x5552
bash-2.05#
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.