Hi All,
How can I find (pattern search with grep/awk/sed) all files containing any IP address pattern in one directory hierarchy and in its sub-directories. The files can contains more than 4 octets in addition to the IP address as shown below. IP address can contain any octet combinations like-
10.132.8.234.12345 ->here first 4 numbers is the ip address, it means the IP address will have a word boundary whenever the first 4 octets are present.
123.12.35.156 etc..
Also I have one array containing unique IP addresses. I want to replace each IP address in files in a directory with different letter for each unique IP, like below-
ip_address1 - 10.232.12.156 -> XX.XXX.XX.XXX
ip_address2 - 10.28.9.136 -> YY.YY.Y.YYY
ip_address3 - 9.10.132.29 -> S.SS.SSS.SS (with some other letter and likewise..)
The above ip addresses are only for demonstration purposes here.It may be valid or invalid. Also each IP address should be replaced with equal number of letter X or Y or some other letter. The logic should work in korn shell on both Linux and Solaris OS.
Some sample logic will be like-
for file in directory
do
for str in ${ipaddr
[*]} # ip address array
do
#replace the ip address 'str' in 'file' with unique letter for each unique IP as mentioned above
# some grep / awk or other pattern matching for IP search and replace logic here
;
done
done
Sorry for this broken script syntax as I am not an advanced user with scripting knowledge.
If awk/nawk/gawk is used, please tell me what is the exact syntax to work it both on linux and Solaris OS.
Thanks in advance for your precious inputs.