blob: 880518e6b93964d1186944bcbe42bed8f4cab872 [file] [log] [blame]
Sivas SRR1fb58622017-04-14 05:44:32 -05001#!/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.
12ip_addr="${1}" ; shift
13file_path="${1}" ; shift
14
15# Validate arguments.
16if [ -z "${ip_addr}" ] ; then
Patrick Williams90dfee32022-12-08 06:52:46 -060017 echo "**ERROR** You must provide an IP address as the first positional" \
18 "parameter." >&2
19 exit 1
Sivas SRR1fb58622017-04-14 05:44:32 -050020fi
21
22if [ -z "${file_path}" ] ; then
Patrick Williams90dfee32022-12-08 06:52:46 -060023 echo "**ERROR** You must provide a file path as the second positional" \
24 "parameter." >&2
25 exit 1
Sivas SRR1fb58622017-04-14 05:44:32 -050026fi
27
28ip_addr_regex=`echo ${ip_addr} | sed 's/\(\.\)/\\\./g'`
29sed -i 's/'${ip_addr_regex}'/DUMMYIP/g' ${file_path}