Thursday, February 19, 2009

AWK - Replacing Strings in columns

Say we have a hosts file map on a NIS based network (or even a simple hosts file for a sake of simplicity) the network department decided to change one of the VLANS (for example from 100 to 200) as part of some infrastructure organizational change. We have thousands of entries that require update:

the host file looks like this: server1 server2 server3

awk '{gsub("100","200");print}' /etc/hosts

awk will acomplish this task as a charm, simple - yet very powerful editor.

No comments: