Ignore:
Timestamp:
11/28/14 15:55:42 (10 years ago)
Author:
aclsce
Message:

Added functionality to add the attribute (if it does not exist) and its value related to an id in xml files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh

    r1116 r1146  
    12801280      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" $filein > $filein.tmp 
    12811281    else 
    1282       # Case to modify the attribute value 
    1283       IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}" 
    1284       sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" $filein > $filein.tmp 
     1282          # Check if keyattrib is set on the same line as keyid 
     1283        if [  $( grep -w $keyid $filein | grep $keyattrib | wc -l ) = 1 ] ; then 
     1284            # Case to modify the attribute value 
     1285            IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}" 
     1286            sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" $filein > $filein.tmp 
     1287        else 
     1288            # Case to add the attribute and its value 
     1289             IGCM_debug_Print 1 "Now add in ${filein} for id=${keyid} the attribute ${keyattrib} to the value ${value}" 
     1290             sed -e "/id=\"${keyid}\"/s/\/>/ ${keyattrib}=\"${value}\"\/>/" $filein > $filein.tmp 
     1291        fi 
    12851292    fi 
    12861293    \mv $filein.tmp $filein 
Note: See TracChangeset for help on using the changeset viewer.