ksh: How do I resolve ip addr in a text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh: How do I resolve ip addr in a text file?
# 1  
Old 03-12-2012
ksh: How do I resolve ip addr in a text file?

Hi,

I need to resolve IP to names in a text file. I was thinking of using some unix commands. Ksh.

Text in file contains a lot of these entries:

Code:
..
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.86.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 (10.107.22.12/1947)
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.100.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 (10.107.22.12/1947)
..

I would like to get this result:

Code:
 
..
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.86.6.20/3678 (10.86.6.20/3678) to inside:10.107.22.12/1947 <SERVERA> (10.107.22.12/1947)
20 6 <166>%ASA-6-302013: Built inbound TCP connection 12690562 for inside2:10.100.6.20/3678 <SERVERC> (10.86.6.20/3678) to inside:10.107.22.12/1947 <SERVERB> (10.107.22.12/1947)
..

So the script should nslookup IP and add the text. But if the IP starts with = 10.86.6 , do not resolve the ip address.

Is that possible ?

Thanks in advanced.


regards


Hasselhaven

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 03-12-2012 at 06:26 AM..
# 2  
Old 03-13-2012
please help..... Could it be made with AWK ?
# 3  
Old 03-13-2012
Well, I suppose the tools to use would be nslookup or host (if your OS has that available)

A cheap and nasty host based answer in ksh could be:-
Code:
#!/bin/ksh
cat inputlogfile | while read a1 a2 a3 a4 a5 a6 a7 a8 a9 first a11 a12 second a14
do
   f="${first%\/*}"         # Trim off chars after the slash
   f="${f#*:}"              # Trim of chars before the colon
   s="${second%\/*}"        # Trim off chars after the slash
   s="${s#*:}"              # Trim of chars before the colon

   if [ "$f" = "${f%10.86.6.*}" ]
   then
      host $f | read firstdns rest
   else
      firstdns=
   fi

   if [ "$s" = "${s%10.86.6.*}" ]
   then
      host $s | read seconddns rest
   else
      seconddns=
   fi

   echo "$a1 $a2 $a3 $a4 $a5 $a6 $a7 $a8 $a9 $first $firstdns $a11 $a12 $second $seconddns $a14"
done

Probably miles better to do this with an awk but for a small input file then this might suffice.




Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 03-13-2012
Here's an awk to try:
Code:
awk '
  NF==2 && $2!=x{
    split($2,H,"/")
    if(H[1]!~excl){
      while("host "H[1]|getline h)
      sub(/\.?\n$/,x,h)
      sub($2,$2 RS h)
    }
  }
  1
' FS=: OFS=: RS=" " ORS=" " excl="^10\.86\.6" infile


Last edited by Scrutinizer; 03-13-2012 at 10:21 AM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh / AIX - Differences between lists to a text file

This seems pretty simple, but I cant figure it out. I get stumped on the simple things. I am running two commands 1) take a listing a directory of files, and filter out the doc_name (which is in a series of extracted files), and place it in a file. ls -l | awk '{print $9}' | grep... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

Insert text in file using two variables. (ksh)

I want to insert text into a file using ksh script. The text is going above a closing </body> tag. In the text are two variables. I thought I found how to do it, inexplicably still, using awk, but ran into some problems and time has gone by too fast. The problems using awk came when I added... (4 Replies)
Discussion started by: robin_simple
4 Replies

3. Shell Programming and Scripting

KSH - Text from input file truncated while converting it to excel

Dear Members, I am using the attached script to convert a input file delimited by '|' to excel. However, while processing the attribute change_reason, the whole content of the text under change_reason is not displayed completely in the cell in excel. It is truncated after only first few words.... (1 Reply)
Discussion started by: Yoodit
1 Replies

4. Shell Programming and Scripting

KSH - XML file from Text file

Hello Members, I have to create a script to parse a text file in the following format: Increment By:1 Max Value:999999 Related Table: Dummy_table Related Table Column: dummy_id Sequence Name: dummy_table_1SQ Start With:1 and create an xml file from the above text file using KSH... (4 Replies)
Discussion started by: Yoodit
4 Replies

5. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

6. Shell Programming and Scripting

Need assistance to resolve the KSH issue

am running the small script below. count_a=48 count_b=48 if ; then echo "Count matched" else echo "count not matched" fi I got the below output. /bin/ksh: [48: not found count not matched It was giving the same error when I ran in another box. But I inculded /bin/ksh in the... (10 Replies)
Discussion started by: sathik
10 Replies

7. Shell Programming and Scripting

inserting subscriber no in text file using KSH....

:confused:Dears , I have text file I need to insert the subscriber number at position 32, and need to keep the next field at position 53 (no increasing of the record lenght), I mean I just want to replace the spaces at position 32 with subscirber number . for example A B A ... (1 Reply)
Discussion started by: atiato
1 Replies

8. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

9. Shell Programming and Scripting

I want to get timestamp from a text file using ksh

for example : 07:25 Thanks (1 Reply)
Discussion started by: vinna
1 Replies

10. AIX

AIX 5.3 , gensyms command, translate 32 bit addr to 64 bit addr

I am trying to map the information from the gensyms command, Its gives information about the various symbols info like symbol type, addr offset, and the main libraries addr starting point. My problem is , how do I map this 32 bit addr to a 64 bit addr, I am trying to extract Segment # information... (0 Replies)
Discussion started by: mrmeswani
0 Replies
Login or Register to Ask a Question