[CentOS] OT: Script Help

Sun May 19 00:55:51 UTC 2013
Leon Fauster <leonfauster at googlemail.com>

Am 19.05.2013 um 02:31 schrieb James Pifer <jep at obrien-pifer.com>:
> On 5/18/2013 3:23 PM, Larry Martell wrote:
>> On Sat, May 18, 2013 at 1:15 PM, James Pifer <jep at obrien-pifer.com> wrote:
>> 
>> cat file | sed -e's/CN=DATA.OU=\(.*\)\.O=CO/CN=\1_DATA.OU=\1.O=CO/'
> 
> Larry,
> 
> 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!


$ export file=FILENAME
$ for i in $(cat $file) ; do TAG=$(echo $i | cut -d. -f2 |cut -d= -f2) ; echo $i | sed s/CN=/CN=${TAG}_/ ; done

--
LF