This might be a programming teaser!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting This might be a programming teaser!
# 1  
Old 12-22-2008
This might be a programming teaser!

Hi gurus,

I have done my best to be as precisely as possible with this.
Besides giving the format of file a and file b and the result file
I have also given the algorithm as I have figured out.
I will try to do this and I hope that some of you could help
me to solve this or better yet present me with a solution.
This could really help my learning experience!.

Thank you

Please read below for a carefull explanation of the whole task

>>>>>>>>>>>>>>
File A

Type;Owner;Prefix;AddressType;hostType;Bitmask;BlockType;isSubnet
Block;Company;172.16.0.0;IPv4;;16;normal;ordinary;;;;;
Block;Company;172.16.0.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.0.0;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.0.128;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.1.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.1.0;IPv4;;25;normal;ordinary;;;;;;;"operations";"noc"
Block;Company;172.16.1.128;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.2.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.2.0;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.2.0;IPv4;;27;"address_set";ordinary;;;;;;;

>>>>>>>>>>>>>>>>>>>>>>
File B

Host;Company;172.16.1.1;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.4;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.5;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.19;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.20;IPv4;user;;;;;;;;;;;;;;;om-zl-hs4a077-cs01.network.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.31;IPv4;user;;;;;;;;;;;;;;;sx11.operations.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.88;IPv4;user;;;;;;;;;;;;;;;cdsrv03.operations.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.127;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.129;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.1;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.4;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.5;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.7;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.8;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.9;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.10;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;

>>>>>>>>>>>>>>>>>>>>>>>>>
Result File

Type;Owner;Prefix;AddressType;hostType;Bitmask;BlockType;isSubnet
Block;Company;172.16.0.0;IPv4;;16;normal;ordinary;;;;;
Block;Company;172.16.0.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.0.0;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.0.128;IPv4;;25;normal;ordinary;;;;;;;
Block;Company;172.16.1.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.1.0;IPv4;;25;"address_set";ordinary;;;;;;;"operations";"noc"
Host;Company;172.16.1.1;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.4;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.5;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.19;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.1.20;IPv4;user;;;;;;;;;;;;;;;om-zl-hs4a077-cs01.network.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.31;IPv4;user;;;;;;;;;;;;;;;sx11.operations.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.88;IPv4;user;;;;;;;;;;;;;;;cdsrv03.operations.company;;;;;;;;;;;;;;;;
Host;Company;172.16.1.127;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Block;Company;172.16.1.128;IPv4;;25;"address_set";ordinary;;;;;;;
Host;Company;172.16.1.129;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Block;Company;172.16.2.0;IPv4;;24;normal;ordinary;;;;;;;
Block;Company;172.16.2.0;IPv4;;25;"address_set";ordinary;;;;;;;
Host;Company;172.16.2.1;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.4;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.5;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.7;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.8;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.9;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Host;Company;172.16.2.10;IPv4;user;;;;;;;;;;;;;;;N/A;;;;;;;;;;;;;;;;
Block;Company;172.16.2.0;IPv4;;27;"address_set";ordinary;;;;;;;

>>>>>>>>>>>>>
The way I think it could be solved


I want to solve this by reading file A line by line.
If column 1 of a line is equal to Block, then read column 3 (prefix) and save the result temporarily.
Next read column 3 (prefix) of the next line and compare it with the previous line, if the value is
equal to the previous line we proceed with the next line. We will not go to the next line if we find
a value of column 3 on the next line which is greater than the value of column 3 on the current line.
Now that we are on a line where the value of column 3 of the next line is not equal to the value of
column 3 of the previous line we will do the work. First we change column 7 to be equal to "address_set".
Next we read column 6 (which is by now the most specific bitmask) of the current line.
With column 3 and 6 from the current line we calculate all possible addresses including the network and
broadcast address (e.g if column 3 is 10.10.10.0 and column 6 25, we have addresses 10.10.10.0
to 10.10.10.127). With this set of calculated IP addresses we will compare against column 3 of each line
of File B. If there is a match the whole line of File B where the match has been found is copied below
the line in File A where we are currently, and next we move to this new added line.
The line we have copied from file B is deleted from File B and copied to a separate file called processed.
When we have processed all calculated IP addresses we will look for the next line with a value of Block
in column 1. From there on we will repeat the whole process again. We keep doing this till there are no
more lines in File A to process.

LJ
# 2  
Old 12-29-2008
So use your algorithm and awk like this:
Code:
awk -F\; 'FILENAME=="fileA" { processA; } FILENAME=="fileB" { processB; } '\
'{ # do something here for both files after processing in processA and processB }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Cyber Dystopia Teaser (720 HD)

Working on a new cybersecurity, dystopian world series and made a short 2 min teaser today. Cyber Dystopia (720 HD) https://www.youtube.com/watch?v=g9Ca07J_YC8 If anyone has any ideas for the story, please write out some story lines in the comments and join the production team! (1 Reply)
Discussion started by: Neo
1 Replies

2. Shell Programming and Scripting

sed regexp teaser

G'day, Here's a teaser for a sed guru, which I surely am not one, as even my basic sed skills are rusted from years of not practising ... lol Ok ... we have a string of digits such as: 632413741610252847552619172459483022433027602515212950543016701812771409213148672112 we want it split... (9 Replies)
Discussion started by: naderra
9 Replies

3. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

4. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

5. Programming

Brain Teaser Extended

Hi Gurus, To the Brain Teaser, if I add another condition, say the executable should not be altered, how the program should be altered? (no perl please, purely C). I forgot to mention this condition my staff had mentioned. ( forgot then and got now :D ) The program executed the first time... (4 Replies)
Discussion started by: vrk1219
4 Replies

6. Programming

C Programming - Hardware Programming

Can someone help me on suggesting some ways to access the memory content in RAM directly from C/C++ source code. Please provide me any book name or any URL so that I can get an exhaustive knowledge over it. If possible please give me some tips on interacting with hardwares directly through... (3 Replies)
Discussion started by: nandumishra
3 Replies

7. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

8. Programming

C Brain Teaser

Dear Gurus, I have encountered a C question, which I thought of sharing with you. This question was asked by one of my technical training staff...Though my training was over I'm still thinking of a solution for this.. Write a C program to do a small task(lets say just simply printing a "Hello... (34 Replies)
Discussion started by: vrk1219
34 Replies

9. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies

10. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question