To find the IP adress in the log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find the IP adress in the log file
# 8  
Old 03-08-2009
Quote:
Originally Posted by ldapswandog
cat test11.txt | awk '{print $NF}' | sort | uniq -c | sort -n | grep "[3-9] "
I count 5 pipes! You could enter the Useless Use of Cat Contest! (no offense!) Smilie
Useless Use of Cat Award

All that is possible in a awk one-liner with no piping. Can the OP provide sample file so that we can demonstrate the terseness of awk?
# 9  
Old 03-08-2009
I offered the non-awk solution because it is self explanatory what it is doing and it uses commands that are used daily by most Unix users. The awk solution with no explanation what it is doing, for those like myself that are not familiar with awk, is just confusing. If parsing out IP addresses is an action that needs to be repeated often, I suggest using Perl, for two reasons. One, it is more efficient that shell solutions and two it is portable even to Windows systems so has a higher reuse value.
# 10  
Old 03-08-2009
I agree that there is a tendency for awk coder to be as terse as possible but you can write awk code that is as readable as perl. Awk inspired Larry Wall to write Perl. So there is a little bit of awk philosophy and coding style in perl. And you can also obfuscate your code in perl:
Code:
#:: ::-| ::-| .-. :||-:: 0-| .-| ::||-| .:|-. :||
open(Q,$0);while(<Q>){if(/^#(.*)$/){for(split('-',$1)){$q=0;for(split){s/\|
/:.:/xg;s/:/../g;$Q=$_?length:$_;$q+=$q?$Q:$Q*20;}print chr($q);}}}print"\n";
#.: ::||-| .||-| :|||-| ::||-| ||-:: :|||-| .:|

Perl activity Smilie

I still believe that for this type of application (scanning a log file) awk is the best tool for the job. Portable, light and fast, very fast (specially the mawk version based on a byte code interpreter). You can also use awk on Linux, *bsd, windows and os-x platforms. Of course you can't do everything with awk. Although I have seen a http server written entirely in awk, when it comes to do complicated things you have to switch to a language like perl, php or python. But, again, for this type of problem, you can't beat awk.

So, if the OP can post a sample file, I promise to come up with a readable solution with comments. No obfuscated code anymore. Promised.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to find repeated IP adress from trace file (.tr)

+ 8.00747 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 63 id 0 protocol 17 offset (bytes) 0 flags length: 540 10.1.3.3 > 10.1.2.4) ns3::UdpHeader (length: 520 49153 >... (11 Replies)
Discussion started by: Nipa
11 Replies

2. IP Networking

adress traffic to tap0

Hello, I have a problem of routing traffic on two virtual interfaces I have created on my machine (CentOs6) By using tunctl I created two virtual interfaces tap1 and tap2 let s imagine I gave them two different address tap1: 10.1.1.1 net 255.255.255.0 tap2: 10.1.2.1 net 255.255.255.0 ... (0 Replies)
Discussion started by: nicandro
0 Replies

3. Shell Programming and Scripting

sort file with email adress

Hi All, I have a file which is "|" pipe delimited. The file has 3 fields. the last field contains email ids which has different host names. I want to sort the file based on host name, which is in 3rd filed and needs to create a file for each host. For example, if out of 1000 records, 10... (6 Replies)
Discussion started by: ace_friends22
6 Replies

4. Shell Programming and Scripting

Trying to get an IP adress from a file

This is probably a real n00b question but i`m not able to figure it out. I have a folder of configuration files that contain IP-adresses. The line i`m interested in looks like this: IP_ADDRESS="123.123.123.1123" Some have muliple ip adresses, so the line will look like : ... (5 Replies)
Discussion started by: DaneV
5 Replies

5. IP Networking

Changing the Ip adress permanently

well i'm trying to change the ip adress on an old alphaserver runing tru64 4.0F using the ifconfig hme0 IP_ADDRESS mask MASK broadcast BROADCAST and when i check it using ifconfig -a it shows the new ip and all is well but when the server is rebooted it reverts back to the old ip (3 Replies)
Discussion started by: randUSR()
3 Replies

6. Shell Programming and Scripting

find log file between two dates

Dear All, Please can you help me to crack this query? If the log files for the task above all had a naming convention of myoutput_YearMonthDay.log (i.e. myoutput_20060215) How would you find only those log files created between the 10th and the 20th of each month going back the last 365 days.... (1 Reply)
Discussion started by: justin_mca
1 Replies

7. HP-UX

Change IP Adress

I want change my IP address and hostname in my machine by use the console. Can any one tell me how can I execute that by command ? Thanks & Regards (1 Reply)
Discussion started by: magasem
1 Replies

8. AIX

Capture IP Adress

hello I need for a script to capture the ip address from the connected user. I have 5 logical partitions. With "who", i have the ip adress, but only for 2 servers. Do you know another command to know the ip address of connected clients ? thank you (14 Replies)
Discussion started by: pascalbout
14 Replies

9. Solaris

IP-Adress

Hello together how can I find a ipadress from a login into remote system console? Thanks a lot Urs (1 Reply)
Discussion started by: MuellerUrs
1 Replies

10. UNIX for Dummies Questions & Answers

MAC-Adress

Hello I need to show my MAC-Adress on a Unix System, is there someone that know how? (2 Replies)
Discussion started by: nkochr
2 Replies
Login or Register to Ask a Question