Re: OT: Script Help

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



From: John Doe <jdmls@xxxxxxxxx>

> From: James Pifer <jep@xxxxxxxxxxxxxxxx>
>>  I have a long file that has lines like this:
>>  some text
>>  some text2
>>  CN=DATA.OU=XYZ.O=CO
>>  some text3
>>  some text4
>> 
>>  I need to change the middle line but leave the rest of the file as is 
>>  like this:
>>  some text
>>  some text2
>>  CN=XYZ_DATA.OU=XYZ.O=CO
>>  some text3
>>  some text4
> 
> IFS="."; cat file | while read L; do set $L; if [ "$1" = 
> "CN=DATA" ]; then P1=${1#CN=}; P2=${2#OU=}; echo 
> "CN=${P2}_$P1.$2.$3"; else echo $*; fi; done

Oops, if DATA means "DATA":
  IFS="."; cat file | while read L; do set $L; if [ "$1" = "CN=DATA" ]; then P=${2#OU=}; echo "CN=${P}_DATA.$2.$3"; else echo $*; fi; done

If DATA is generic:
  IFS="."; cat file | while read L; do set $L; if [ "${1%=*}" = "CN" ]; then P1=${1#CN=}; P2=${2#OU=}; echo "CN=${P2}_$P1.$2.$3"; else echo $*; fi; done

JD
_______________________________________________
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