0

we want to update the following file , in case MACHINE_NAME ended with ".localdomain" then need to add the string linux in the beginning of the word

each MACHINE_NAME comes with single brackets '......'

example of file before changing

['server_primary01.localdomain', 'server_primary02.localdomain', 'server_primary03.localdomain']
EDIT_HOSTS.append( {'HOST' : 'Client0{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'Client{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'Client0{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'Client{0}.localdomain'.format(count+1)} )

example after changing

        ['linuxserver_primary01.localdomain', 'linuxserver_primary02.localdomain', 'linuxserver_primary03.localdomain']
        EDIT_HOSTS.append( {'HOST' : 'linuxClient0{0}.localdomain'.format(count+1)} )
        EDIT_HOSTS.append( {'HOST' : 'linuxClient{0}.localdomain'.format(count+1)} )
        EDIT_HOSTS.append( {'HOST' : 'linuxClient0{0}.localdomain'.format(count+1)} )
        EDIT_HOSTS.append( {'HOST' : 'linuxClient{0}.localdomain'.format(count+1)} )
2

sed solution:

sed -E "s/[^[:space:]']+\.localdomain/linux&/g" file

Sample output:

['linuxserver_primary01.localdomain', 'linuxserver_primary02.localdomain', 'linuxserver_primary03.localdomain']
EDIT_HOSTS.append( {'HOST' : 'linuxClient0{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'linuxClient{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'linuxClient0{0}.localdomain'.format(count+1)} )
EDIT_HOSTS.append( {'HOST' : 'linuxClient{0}.localdomain'.format(count+1)} )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.