[CentOS] OT: Script Help

Sun May 19 00:56:28 UTC 2013
zGreenfelder <zgreenfelder at gmail.com>

>
> Thanks for the answer. Still having trouble making it work. Been looking
> at sed for the last two hours. Let me give a specific example of a few
> lines I would want to change:
>
> Let's say my original lines are:
> CN=DATA.OU=XYZ.O=CO
> CN=DATA.OU=XYY.OU=MEM.O=CO
> CN=DATA.OU=XZZ.OU=OOP.O=CO
>
> I want them to look like:
> CN=XYZ_DATA.OU=XYZ.O=CO
> CN=XYY_DATA.OU=XYY.OU=MEM.O=CO
> CN=XZZ_DATA.OU=XZZ.OU=OOP.O=CO
>
> So I need to take the data after the FIRST OU and stick in front of DATA
> with an _ in between. The rest of the line then remains the same.
>
> Hope it makes sense. Appreciate the help!
>
> Thanks,
> James
>

I can't say for sure it'll do what you want, it should be tested
extensively to make sure it doesn't destroy your car, sleep with your
wife,steal your money, etc etc all the warnings I can give, but I'd
suggest perl.   this is something I cooked up on a conf call:


[zep at nemesis throwaway]$ cat centoslist
CN=DATA.OU=XYZ.O=CO
CN=DATA.OU=XYY.OU=MEM.O=CO
CN=DATA.OU=XZZ.OU=OOP.O=CO
[zep at nemesis throwaway]$ cat cent-req
#!/usr/bin/perl

open(FH,"< $ARGV[0]") || die "can not open $ARGV[0]:";

while(<FH>){
  chomp $_;
  if($_=~/OU=/){
     $prepend=$_;
     @prepend=split(/.OU=/,$_);
     $mod=$prepend[1];
     $mod=~s/\..*//;
     $_=~s/^CN=/CN=${mod}_/;
  }
  print "$_\n";
}
[zep at nemesis throwaway]$ perl cent-req centoslist
CN=XYZ_DATA.OU=XYZ.O=CO
CN=XYY_DATA.OU=XYY.OU=MEM.O=CO
CN=XZZ_DATA.OU=XZZ.OU=OOP.O=CO
[zep at nemesis throwaway]$




--
Even the Magic 8 ball has an opinion on email clients: Outlook not so good.