Sponsored Content
Top Forums Shell Programming and Scripting AWK script to detect webpages from file Post 302406258 by ROFL on Monday 22nd of March 2010 12:10:01 PM
Old 03-22-2010
AWK script to detect webpages from file

Hi guys I'm very new to unix and I have to create an awk script that detects webpage addresses from a file/webpage and outputs how many times each webpage was detected.e.g. if my file was:

www.google.com
www.facebook.com
www.google.com

the output should be:

www.google.com x2
www.facebook.com x1

However I cannot get this to work at the moment, can somebody please tell me what is wrong with my code:

Code:
BEGIN {print "Running script on the file",ARGV[1]} 

/www*/{for(i=1;i<=NF;i++)
    {if($i ~ /^www/)
        link[NR] = $i
        occurs[NR] = 1
    }

}
{for(i = 1; i < NR; i++) 
    {if(link[NR] == link[i])
        occurs[i]++
        link[NR] = "repeat"    
    }
}
{print link[NR],"occurs",occurs[NR],"times"}
END {print "Ending"}

Thank you!

Last edited by ROFL; 03-22-2010 at 01:47 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix script to detect new file entry in directory

Hi All, I want to detect each new file coming / getting created in unix directory. When every new file came to directory, i have to get its details like its size , date and time stamp and store it into another file. Could any one please tell me , how i can achieve that? Thanks. (13 Replies)
Discussion started by: james_1984
13 Replies

2. UNIX for Dummies Questions & Answers

how to detect my script is already running

I have a script which must not be run more than once at any given time. THis script will be scheduled to run every 20 mins as a cron job. In my script can i have logic to say if this script is already running from the previous cron, then exit. How do i go about doing that. If you describe the... (11 Replies)
Discussion started by: rmulchandani
11 Replies

3. Shell Programming and Scripting

AWK script to detect webpages from file

Hi guys I'm very new to unix and I have to create an awk script that detects webpage addresses from a file/webpage and outputs how many times each webpage was detected.e.g. if my file was: (Note: The symbol " was added to stop them being created into links) "www.google.com"... (1 Reply)
Discussion started by: ROFL
1 Replies

4. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

5. Shell Programming and Scripting

Script to detect dynamic ip change and update to config file

Hi All, I am newbie here and request your assistance. I have a service running on public ip, but since I have a dynamic IP it keeps on changing and every time I need to manually get the new ip and add to the config file and restart the service. This has become bit time consuming. Hence, I... (4 Replies)
Discussion started by: Shaan_Shaan
4 Replies

6. Shell Programming and Scripting

How to detect empty field in awk ?

Hi ! programmers I have a need of detecting empty field in file my file looks like this 40.900|-71.600|1.6|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|5.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|7.8|20|1|1961|21.00|3.700||1|US|28035|10029370|31... (7 Replies)
Discussion started by: Dona Clara
7 Replies

7. Shell Programming and Scripting

Help with detect with regex and move script

Hi all, I am needing some help with a script that will search for a video file by known extensions and then do a pattern search (I'm guessing via regex) and then based on a match of one type of another move the file to an assigned directory. I would like to do this with either a shell script... (7 Replies)
Discussion started by: Simplify
7 Replies

8. Shell Programming and Scripting

How to detect awk and nawk?

I have 10 scripts which use awk/nawk extensively. I have to always change awk to nawk and nawk to awk when i deploy all my scripts to different types of servers as some support nawk while other support awk. Can you propose a solution that without having to tweak my 10 scripts at several... (8 Replies)
Discussion started by: mohtashims
8 Replies

9. Shell Programming and Scripting

awk script to detect specific string in a log file and count it

Hello, can someone guide me on this? I don't know what is the best approach, (awk script, shell script) I am using RedHat Linux version 6.5. There is a third party application deployed on that server. This app by default generates 5 log files and each file is 20MB. These log rollover... (5 Replies)
Discussion started by: ktisbest
5 Replies

10. Shell Programming and Scripting

How to detect url in use in a script?

Hello, I have a small script and it runs from web application in below format: pipe:///path_to_myscript.sh url1 url2 url3 myscript.sh: #!/bin/bash count=0 while do count=$((count+1)) exec 3>&1 ((ffmpeg -i $1 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \ while read LINE; do echo... (9 Replies)
Discussion started by: baris35
9 Replies
NE_ADDR_RESOLVE(3)						neon API reference						NE_ADDR_RESOLVE(3)

NAME
ne_addr_resolve, ne_addr_result, ne_addr_first, ne_addr_next, ne_addr_error, ne_addr_destroy - functions to resolve hostnames to addresses SYNOPSIS
#include <ne_socket.h> ne_sock_addr *ne_addr_resolve(const char *hostname, int flags); int ne_addr_result(const ne_sock_addr *addr); const ne_inet_addr *ne_addr_first(ne_sock_addr *addr); const ne_inet_addr *ne_addr_next(ne_sock_addr *addr); char *ne_addr_error(const ne_sock_addr *addr, char *buffer, size_t bufsiz); void ne_addr_destroy(ne_sock_addr *addr); DESCRIPTION
The ne_addr_resolve function resolves the given hostname, returning an ne_sock_addr object representing the address (or addresses) associated with the hostname. The flags parameter is currently unused, and must be passed as 0. The hostname passed to ne_addr_resolve can be a DNS hostname (e.g. "www.example.com") or an IPv4 dotted quad (e.g. "192.0.34.72"); or, on systems which support IPv6, an IPv6 hex address, which may be enclosed in brackets, e.g. "[::1]". To determine whether the hostname was successfully resolved, the ne_addr_result function is used, which returns non-zero if an error occurred. If an error did occur, the ne_addr_error function can be used, which will copy the error string into a given buffer (of size bufsiz). The functions ne_addr_first and ne_addr_next are used to retrieve the Internet addresses associated with an address object which has been successfully resolved. ne_addr_first returns the first address; ne_addr_next returns the next address after the most recent call to ne_addr_next or ne_addr_first, or NULL if there are no more addresses. The ne_inet_addr pointer returned by these functions can be passed to ne_sock_connect to connect a socket. After the address object has been used, it should be destroyed using ne_addr_destroy. RETURN VALUE
ne_addr_resolve returns a pointer to an address object, and never NULL. ne_addr_error returns the buffer parameter . EXAMPLES
The code below prints out the set of addresses associated with the hostname www.google.com. ne_sock_addr *addr; char buf[256]; addr = ne_addr_resolve("www.google.com", 0); if (ne_addr_result(addr)) { printf("Could not resolve www.google.com: %s ", ne_addr_error(addr, buf, sizeof buf)); } else { const ne_inet_addr *ia; printf("www.google.com:"); for (ia = ne_addr_first(addr); ia != NULL; ia = ne_addr_next(addr)) { printf(" %s", ne_iaddr_print(ia, buf, sizeof buf)); } putchar(' '); } ne_addr_destroy(addr); SEE ALSO
ne_iaddr_print AUTHOR
Joe Orton <neon@lists.manyfish.co.uk> Author. COPYRIGHT
neon 0.30.0 31 July 2013 NE_ADDR_RESOLVE(3)
All times are GMT -4. The time now is 12:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy