[CentOS] OT: Script Help

Tue May 21 18:45:17 UTC 2013
Peter Eckel <lists at eckel-edv.de>

Hi James, 

  perl -pne 's/^(CN=)(DATA\.OU=)((.*?)\.O=CO)$/$1$4_$2$3/' /file/name

or, if you prefer in-place editing, 

  perl -i.bak -pne 's/(CN=)(DATA\.OU=)((.*?)\.O=CO)/$1$4_$2$3/' /file/name

which replaces the file with the modified version and keeps a .bak file around for security. 

Example: 

lagavulin:~ pete$ cat /tmp/test
some text
some text2
CN=DATA.OU=XYZ.O=CO
some text3
some text4
some text
some text2
CN=DATA.OU=RST.O=CO
some text3
some text4
some text
some text2
CN=DATA.OU=ABC.O=CO
some text3
some text4
some text
some text2
CN=DATA.OU=UVWXYZ.O=CO
some text3
some text4

lagavulin:~ pete$  perl -pne 's/(CN=)(DATA\.OU=)((.*?)\.O=CO)/$1$4_$2$3/' /tmp/test
some text
some text2
CN=XYZ_DATA.OU=XYZ.O=CO
some text3
some text4
some text
some text2
CN=RST_DATA.OU=RST.O=CO
some text3
some text4
some text
some text2
CN=ABC_DATA.OU=ABC.O=CO
some text3
some text4
some text
some text2
CN=UVWXYZ_DATA.OU=UVWXYZ.O=CO
some text3
some text4

I guess that's what you need. 

Best regards, 

  Peter.