From: John Doe <[email protected]>
> From: James Pifer <[email protected]>
>> 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
[email protected]
http://lists.centos.org/mailman/listinfo/centos