Need to get this code to run through whole text file while changing a field
Hi, I have code to change to convert IP addresses to integers but you have to give it an address
echo 194.169.240.130 | perl -ne 's/(\d+)\.(\d+)\.(\d+)\.(\d+)/$1<<24|$2<<16|$3<<8|$4/e;print' this gives something like 3265917058 However I want it to covert these 2 IP addresses that are in the same line (there are multipe lines of data the same in the same file) as below 'Mop-21050905','auth','info','info','26','2009-10-09 12:45:20','snort','snort[4574]: [1:2050:14] SQL version overflow attempt [Classification: Attempted Administrator Privilege Gain] [Priority: 1]: {UDP} 202.103.9.51:1096 -> 95.224.96.106:1434',8764657 change it to 'Mop-21050905','auth','info','info','26','2009-10-09 12:45:20','snort','snort[4574]: [1:2050:14] SQL version overflow attempt [Classification: Attempted Administrator Privilege Gain] [Priority: 1]: {UDP} 329292829:1096 -> 2888901919:1434',8764657 otherwise i have to go through each individual line to do it, there are too many!! I think sed would do it, but want to have the changes kept in the same file. Any ideas anybody? |
The equivalent SED command uses the "g" flag to change all occurences on a line. I would think PERL would have something similar.
Quote:
|
Yes the perl syntax for global change is /g. Eg
Code:
$string =~ s/regex/replacement/g; |
Should be pretty easy. Try this:
Code:
sed -i 's/\.//g' $filename Good luck! |
All times are GMT -5. The time now is 04:57 PM. |