Re: OT: Script Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



>
> 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@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@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@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@nemesis throwaway]$




--
Even the Magic 8 ball has an opinion on email clients: Outlook not so good.
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux