Sivas SRR | 1fb5862 | 2017-04-14 05:44:32 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This program will modify a file by substituting all instances of a specified |
| 4 | # IP with "DUMMYIP". This is useful for making the IP address generic and thus |
| 5 | # searchable. |
| 6 | |
| 7 | # Description of argument(s): |
| 8 | # ip_addr An IP address. |
| 9 | # file_path The path to a file which is to be modified. |
| 10 | |
| 11 | # Get arguments. |
| 12 | ip_addr="${1}" ; shift |
| 13 | file_path="${1}" ; shift |
| 14 | |
| 15 | # Validate arguments. |
| 16 | if [ -z "${ip_addr}" ] ; then |
| 17 | echo "**ERROR** You must provide an IP address as the first positional" \ |
| 18 | "parameter." >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | if [ -z "${file_path}" ] ; then |
| 23 | echo "**ERROR** You must provide a file path as the second positional" \ |
| 24 | "parameter." >&2 |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | ip_addr_regex=`echo ${ip_addr} | sed 's/\(\.\)/\\\./g'` |
| 29 | sed -i 's/'${ip_addr_regex}'/DUMMYIP/g' ${file_path} |