To add a number at the end of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To add a number at the end of the line
# 1  
Old 08-29-2009
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
# 2  
Old 08-29-2009
Hi.

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

# 3  
Old 08-29-2009
Its worked out, thanks a bunch...
# 4  
Old 09-22-2009
Hi,

There are ip with double ..

Code:
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

Last edited by vgersh99; 09-22-2009 at 10:15 AM.. Reason: code tags, PLEASE!
# 5  
Old 09-22-2009
Try this...

Code:
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...

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

# 6  
Old 09-22-2009
You can use sed
Code:
sed 's/\.$//;s/.*/&.0\/8/' file

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

# 7  
Old 09-22-2009
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

Last edited by gsiva; 09-22-2009 at 12:59 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add line at the end

How to add a comma at the end of each line in this file?30 1412 30 3352 30 5254 30 5543 30 7478 3 28 3 30 3 39 3 54 3 108 3 152 3 178 3 182 3 214 3 271 3 286 3 300 3 348 3 349 3 371 (3 Replies)
Discussion started by: gunjan
3 Replies

2. Shell Programming and Scripting

adding line number to *end* of records in file

Given a file like this: abc def ghi I need to get to somestandardtext abc1 morestandardtext somestandardtext def2 morestandardtext somestandardtext ghi3 morestandardtext Notice that in addition to the standard text there is the line number added in as well. What I conceived is... (4 Replies)
Discussion started by: edstevens
4 Replies

3. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

4. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

5. Shell Programming and Scripting

how to add ; at the end of last line

hi, i have file which is having large sql query eg : i am executing this sql file but now i want to add ; after query on same line i.e. i should look like any idea how to achieve it ? (6 Replies)
Discussion started by: crackthehit007
6 Replies

6. Shell Programming and Scripting

Capturing a number at the end of line and store it as variable

Hello, Would someone guide me on how to write a shell script the would search for a phone no using at the end text file using sed or awk and store it in a varaible or print it. The text file is in this form text or numbers in first line text or numbers in second line . . . Firsname... (6 Replies)
Discussion started by: amuthiga
6 Replies

7. UNIX for Advanced & Expert Users

Add line numbers to end of each line

Hi i would like to add line numbers to end of each line in a file. I am able to do it in the front of each line using sed, but not able to add at the end of the file. Can anyone suggest The following code adds line number to start of each line sed = filename | sed 'N;s/\n/\t/' how can i... (5 Replies)
Discussion started by: rudoraj
5 Replies

8. Shell Programming and Scripting

Number a list at end of line using 'sed'

Hi All I have a script which has produced a list, I have used 'sed' to number my list, but i want to list at end of line with the first line starting at zero (0) and brackets round it ie My List i want Hello (0) this (1) day (2) can (3) be (4) sed '/./=' filename | sed '/./N; s/\n/) /'... (5 Replies)
Discussion started by: chassis
5 Replies

9. Shell Programming and Scripting

Add a new end of line

Hi, Does anyone know if its possible to add something like an end of line like c or java in unix? dirs=/home/nosnam var='' for dir in $dirs do listDirs=`ls -d1 $dir/*` for eachList in $listDirs do listRepos=`du -ks $eachList | awk '{ x+=$1 }; END { print x... (4 Replies)
Discussion started by: nosnam
4 Replies

10. Shell Programming and Scripting

Select matches between line number and end of file?

Hi Guys/Gals, I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts. Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Discussion started by: Jerrad
4 Replies
Login or Register to Ask a Question