我们要更新以下文件,以防 MACHINE_NAME 结尾“.localdomain”然后需要在单词的开头添加字符串 linux
每个 MACHINE_NAME 都带有单括号“......”
更改前的文件示例
['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)} )
更改后的示例
['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)} )
答案1
sed
解决方案:
sed -E "s/[^[:space:]']+\.localdomain/linux&/g" file
示例输出:
['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)} )