To add a number at the end of the line

Hi Folks,

Using the Vi, how can I add a numbers at the end of the line.
For eg: I have the numbers in the file as:
58.125.33
22.58.68
25.144.225
114.25.38

I need to add .0/8 at the end of all the line. So, it should be like
58.125.33.0/8
22.58.68.0/8
25.144.225.0/8
114.25.38.0/8

Hi.

:%s/.*/&.0\/8

Its worked out, thanks a bunch...

Hi,

There are ip with double ..

93.74.78..0/8
70.80.27..0/8
88.87.30..0/8
83.4.167..0/8

How can I change this to single dot...

Regards
Siva

Try this...

awk -v OFS="" '{print $1,".0/8"}' file

---------- Post updated at 05:28 AM ---------- Previous update was at 05:17 AM ----------

And for the IP double...

awk  '{gsub("[.]{2}",".",$0)}1' file

You can use sed

sed 's/\.$//;s/.*/&.0\/8/' file

or awk

awk -F. '{$0=((!$NF)?$0:$0FS)"0/8"}1'  file

Thanks a lot, it worked out..

Now, I would like to automate the process via cron;

Here below the last log from the server:

stybloga ftpd20571 ::ffff:80.99.99. Sun Sep 20 08:52 gone - no logout
stybloga ftpd20569 ::ffff:79.117.15 Sun Sep 20 08:52 gone - no logout
stybloga ftpd20568 ::ffff:95.223.19 Sun Sep 20 08:52 still logged in
stybloga ftpd20553 ::ffff:188.27.12 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20552 ::ffff:85.66.149 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20550 ::ffff:84.227.20 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20534 ::ffff:89.102.22 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20518 ::ffff:89.173.62 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20511 ::ffff:94.19.144 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20509 ::ffff:89.103.12 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20508 ::ffff:86.101.22 Sun Sep 20 08:51 gone - no logout
stybloga ftpd20507 ::ffff:80.2.176. Sun Sep 20 08:51 gone - no logout

Where :
stybloga -> is the username
::ffff:80.2.1 -> ip address connected to the users.

What I am doing right now is

1) last | grep stybloga | awk '{print $3}' > one
2) awk -F. '{$0=((!$NF)?$0:$0FS)"0/8"}1' one > ipblck
3) Using the bash script, I will block the ip's
#!/bin/bash
BLOCKDB=/root/ipblck
IPS=$(grep -Ev "^#" $BLOCKDB)
for i in $IPS
do
iptables -A INPUT -s $i -j DROP
iptables -A OUTPUT -d $i -j DROP
done

So, now what I am trying is, there are different user like the same as above using different ip adderss.

1) Need to check the users in the last log, if a user count exceeds more than of 10 times,
2) Then it should check the third value, which is the ip address . If that do differs with different ip address for the 10 counts then
3) then the ip address should be taken and do as like the process what I have mentioned above.. the 3 steps that I am doing now..

I hope it make sense...

Regards
Siva