Get the ipaddress and align based on the input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the ipaddress and align based on the input file
# 1  
Old 08-02-2012
Get the ipaddress and align based on the input file

Hi All,

I have a file contains below contents, "interfacename/subnet: public (or) interfacename/subnet:cluster_interconnect"

HTML Code:
"en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public
"en0"/10.26.208.0:public,"en1"/192.168.3.0:cluster_interconnect
With the help of the contents i want to make the ouput like below

HTML Code:
  Public IP Address : 169.181.146.79
  Private IP Address 1 : 10.185.81.1
  Private IP Address 2 : 10.185.81.2
sometime it may have 2 cluster_interconnect & sometime it may be 1. Please provide the suggestions. Thanks !

Regards
Kamal
# 2  
Old 08-02-2012
Your output data doesn't really resemble your input. It seems to create .79, .1, .2 out of nowhere -- how does it decide these from .0? Why does it ignore 10.26.208.0? etc, etc.

You'll have to explain the algorithm you want better.
# 3  
Old 08-02-2012
Thanks for the reply, Let me rephrase my question. I need to get the interface name (example en2 -> private en5 -> private en6 -> public)based on those below input file and get the ipaddress for each interface name..... like that i have to do for each line of input file... and get the output as below.

Input file
---------

HTML Code:
"en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public
"en0"/10.26.208.0:public,"en1"/192.168.3.0:cluster_interconnect
Expected Output
-----------------

HTML Code:
  Public IP Address : 169.181.146.79
  Private IP Address 1 : 10.185.81.1
  Private IP Address 2 : 10.185.81.2
Regards
Kamal
# 4  
Old 08-02-2012
Hi,

You could probably get the information this way;

Code:
# ifconfig -a

Regards

Dave
# 5  
Old 08-02-2012
You have not explained anything about what I actually asked.

Where does the .79 come from?

Where does the .1 come from?

Where does the .2 come from?

Why does it ignore 10.26.208.0?

Why does it ignore 192.168.3.0?

What does the interface name have to do with any of it? It doesn't appear in the output at all.
# 6  
Old 08-06-2012
Input data (Only single line) is generated by oracle database itself its stored in config file in each and every Oracle RAC Server as below format

HTML Code:
ex:
if we specify one public & private interface during installation of oracle RAC it will put one entry for public and private as below format in config file 
 
"<interfacename>"/<subnet>:public,"<interfacename>"/<subnet>:cluster_interconnect
 
if we specify one public & two private interface during installation of oracle RAC it will put one entry for public and two private as below format in config file 
 
"<interfacename>"/<subnet>:public,"<interfacename>"/<subnet>:cluster_interconnect,"<interfacename>"/<subnet>:cluster_interconnect
All i am doing now is based on this input stored in the config file i want to convert this to below output

HTML Code:
EX : ifconfig en2  (Ipaddress will be derived from this command)
 
en6 -> public -> <Ipaddress>
en2 -> Private 1 -> <Ipaddress>
en5 -> Private 2 -> <Ipaddress>
Regards
Kamal

Last edited by kamauv234; 08-06-2012 at 05:00 AM..
# 7  
Old 08-06-2012
Making the wild assumption (amongst others) that your ifconfig will produce sth like
Code:
eth0      Link encap:Ethernet  HWaddr 00:1f:c6:4c:d0:e2  
          inet addr:10.1.1.1

this awk program (saved in cmdfile) might do the job:
Code:
BEGIN   {
         while (("ifconfig -a|awk '/Link/ {a=$1; getline; sub(\".*:\",\"\",$2);print a, $2}'"|getline) > 0)
         ip[$1]=$2
         RS="[,\n]"; FS="/"
        }

        {
         gsub("\"","");gsub("([0-9]+[.:])+","",$2); if($2!="public") $2="Private "++pn
        }
        {print $1, "->", $2, "->", ip[$1]}

Execute like awk -f cmdfile inputfile

What it does is in the BEGIN command it executes ifconfig to pipe all the interfaces (identified by "Link" in the same line) and their IP- addresses into array "ip". Then it reads your input file, records separated by ",", to extract the respective interface names, cleans field $2 from the network part, and, if the remainder is not "public", assigns the string "Private " plus a counter. Finally the fields are printed. Hope this fits your needs. You may need to adapt the ifconfig extraction.

Last edited by RudiC; 08-06-2012 at 06:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to align/sort the column pairs of an csv file, based on keyword word specified in another file?

I have a csv file as shown below, xop_thy 80 avr_njk 50 str_nyu 60 avr_irt 70 str_nhj 60 avr_ngt 50 str_tgt 80 xop_nmg 50 xop_nth 40 cyv_gty 40 cop_thl 40 vir_tyk 80 vir_plo 20 vir_thk 40 ijk_yuc 70 cop_thy 70 ijk_yuc 80 irt_hgt 80 I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies

2. Shell Programming and Scripting

How to pass arguments based on input file?

This script is running some exe file we are passing three argumnet below custome key word Want to update script based on input files every time it will take argument from input file below is the input files should take this input put it into the script. k.ksh cd /u/kali/temp ... (8 Replies)
Discussion started by: Kalia
8 Replies

3. Shell Programming and Scripting

Copy data to new file based on input pattern

Hi All, I want to create a new file based on certain conditions and copy only those conditioned data to new file. Input Data is as it looks below. ORDER|Header|Add|32|32|1616 ORDER|Details1......... ORDER|Details2......... ORDER|Details3......... ORDER|Details4............ (10 Replies)
Discussion started by: grvk101
10 Replies

4. Shell Programming and Scripting

Align input fields on one under each other

Hello again, I'm having a issue with a contact form. I want the input fields to be aligned on same row and I really dont know how to do it. I attached a image for you to understand what i am trying to do. <BR> <label for="name" class="required"> Name&nbsp;<strong... (1 Reply)
Discussion started by: galford
1 Replies

5. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

Retaining file versions based on input parameter

Hello Forum. I have the following files in one directory: abc_july01_2013.txt abc_july02_2013.txt abc_july03_2013.txt abc_july04_2013.txt abc_july05_2013.txt abc_july06_2013.txt abc_july07_2013.txt abc_july08_2013.txt If I want to be able to keep the last 5 versions of the file and... (4 Replies)
Discussion started by: pchang
4 Replies

7. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

8. Shell Programming and Scripting

Move input file based on condition

Hello, I have File1 in a directory A, a File2 in a directory B. If the File2 is not empty Then I have to move File1 from directory A to a directory archive Else no action. Is it possible to do this from one command line? Thank you in advance for your answers. Madi (2 Replies)
Discussion started by: AngelMady
2 Replies

9. Shell Programming and Scripting

Copy input file based on condition

Hi, I am new to unix shell programming. I want to write a shell script for a functionality existing in mainframe system. I have one file as below as input 123456 &__987 &12yuq abcdef _ referes to blank condition:whenever the input file is having &__ ,it should be replaced... (4 Replies)
Discussion started by: charan0703
4 Replies

10. Shell Programming and Scripting

How to grep in order based on the input file

Here is an answer rather than a question that I thought I would share. In my first attempt, I was using grep to find a list from file.1 within another file, file.2 which I then needed to paste the output from file.3 to file.1 in the same order. However, the results weren't what I wanted. At... (2 Replies)
Discussion started by: Kelam_Magnus
2 Replies
Login or Register to Ask a Question