Sponsored Content
Top Forums Shell Programming and Scripting awk getline 8 times and if $3 = 8 when subtracted from 1st line,print Post 302844181 by numele on Friday 16th of August 2013 08:03:02 PM
Old 08-16-2013
awk getline 8 times and if $3 = 8 when subtracted from 1st line,print

I have kind of a strange one here. I have a file of consecutive /24 ip blocks. If there are 8 consecutive ip blocks which represent a /20 then I need to print the first line. I played around and did not get the results I need, especially when considering that the highest $3 will be is 255 and then start over to 0.

Here is a sample file
Code:
10.71.192.0
10.71.193.0
10.71.194.0
10.71.195.0
10.71.196.0
10.71.197.0
10.71.198.0
10.71.199.0
10.78.176.0
10.78.177.0
10.78.178.0
10.78.179.0
10.90.25.0
10.90.26.0
10.122.232.0
10.122.233.0
10.122.234.0
10.122.235.0
10.122.236.0
10.122.237.0
10.122.238.0
10.122.239.0
10.144.251.0
10.144.252.0
10.144.253.0
10.144.254.0
10.144.255.0
10.145.0.0
10.145.1.0
10.145.2.0

What I need to see output is:
Code:
10.71.192.0
10.122.232.0
10.144.251.0

I tried something like this but did not get good results
Code:
nawk -F"." '{p=$0; v=$3; getline;getline;getline;getline;getline;getline;getline;getline; d=$3 - v} d = 8 {print p}' myfile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK print a character many times

How can I print a '-' on the same line within awk, say 50 times, without actually typing '-' 50 times? Cheers (3 Replies)
Discussion started by: dbrundrett
3 Replies

2. Shell Programming and Scripting

print any required line by its line no using awk and its NR variable

how to print any required line by its line no using awk and its NR variable for eg: ------------ 121343 adfdafd 21213sds dafadfe432 adf.adf%adf --------------- requied o/p if give num=3 it print: 21213sds -------------------------------------- (2 Replies)
Discussion started by: RahulJoshi
2 Replies

3. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies

4. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

5. Shell Programming and Scripting

GetLine fn always giving last line of the file

Hi, Its bit urget for me to complete. pls help me. I am parsing 2 file 1. INDATA(Data file) 2. GRPFIL(Reference) every record in INDATA should be verified with GRP_DATA. I am seeing the output from only the last line of ref file, its not searching all the lines. INDATA sample... (1 Reply)
Discussion started by: hyperion.krish
1 Replies

6. Shell Programming and Scripting

print whole line if the 1st field contains...

i want to print lines in a file that the 1st field of each line has a Date shape such: yy/mm/dd or on the other hand contains slash "/" . (1 Reply)
Discussion started by: oreka18
1 Replies

7. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

8. Shell Programming and Scripting

How to print a particular character n number of times in a line??

hi, Is it possible to print a particular character n number of times in a line? for example. i am print the following line using echo command.. echo "files successfully moved" i want to count the number of characters that are been displayed. i am doin it using echo "files... (8 Replies)
Discussion started by: Little
8 Replies

9. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

10. UNIX for Dummies Questions & Answers

awk file subtracted by a fix value - conditioned

Hi all... i have been trying to make this work but I have been failing for 6 hours .. I know it should be something simple that I am missing to it would be great if you can help me ... I want to subtract a fixed value (lets set 1) from any value >=1 from the whole file my file looks like ... (4 Replies)
Discussion started by: A-V
4 Replies
xfs_bmap(8)						      System Manager's Manual						       xfs_bmap(8)

NAME
xfs_bmap - print block mapping for an XFS file SYNOPSIS
xfs_bmap [ -adlpv ] [ -n num_extents ] file DESCRIPTION
xfs_bmap prints the map of disk blocks used by files in an XFS filesystem. The map lists each extent used by the file, as well as regions in the file that do not have any corresponding blocks (holes). Each line of the listings takes the following form: extent: [startoffset..endoffset]: startblock..endblock Holes are marked by replacing the startblock..endblock with hole. All the file offsets and disk blocks are in units of 512-byte blocks, no matter what the filesystem's block size is. OPTIONS
-a If this option is specified, information about the file's attribute fork is printed instead of the default data fork. -d If portions of the file have been migrated offline by a DMAPI application, a DMAPI read event will be generated to bring those por- tions back online before the disk block map is printed. However if the -d option is used, no DMAPI read event will be generated for a DMAPI file and offline portions will be reported as holes. -l If this option is used, then <nblocks> blocks will be appended to each line. nblocks is the length of the extent described on the line in units of 512-byte blocks. This flag has no effect if the -v option is used. -n num_extents If this option is given, xfs_bmap obtains the extent list of the file in groups of num_extents extents. In the absence of -n, xfs_bmap queries the system for the number of extents in the file and uses that value to compute the group size. -p If this option is used, xfs_bmap obtains all unwritten (preallocated) extents that do not contain written data. With the -v option, the flags column will show which extents are preallocated/unwritten. -v Shows verbose information. When this flag is specified, additional AG specific information is appended to each line in the following form: agno (startagoffset..endagoffset) nblocks flags A second -v option will print out the flags legend. SEE ALSO
xfs_fsr(8), xfs(5). xfs_bmap(8)
All times are GMT -4. The time now is 12:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy