Counting Instances of a String with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting Instances of a String with AWK
# 1  
Old 09-23-2012
Counting Instances of a String with AWK

I have a list of URLs and I want to be able to count the number of instances of addresses ending in a certain TLD and output and sort it like so.

5 bdcc.com
48 zrtzr.com
49 rvo.com

Input is as so
Code:
ync.org
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
sduzj.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
hmeyy.edu
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
zrtzr.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
rvo.com
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
mnw.edu
bdcc.com
bdcc.com
bdcc.com
bdcc.com
bdcc.com
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu
dhkys.edu

# 2  
Old 09-24-2012
Code:
sort file|uniq -c|grep '\.com$'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting a string between 2 strings...

I have been working on this for a little while and have been unable to come to a solution. Any help would be appreciated. I am working on a UNIX workstation and have a 30-40 meg text file that I am working with. In my real file there is hundreds of Jobs. Example of input file; misc logging data... (1 Reply)
Discussion started by: ny_evan
1 Replies

2. Shell Programming and Scripting

count the number of instances in 2 columns using awk

Input A.1 Q.1 A.1 Q.2 A.1 Q.3 A.2 Q.4 Explanation: Final Output A.1 Q.1 s1 t1 A.1 Q.2 s1 t2 A.1 Q.3 s1 t3 A.2 Q.4 s5 t5 ---------- Post updated 09-28-12 at 03:38 AM ---------- Previous update was 09-27-12 at 09:10 AM ---------- Hi Guys, I was able to do until... (11 Replies)
Discussion started by: quincyjones
11 Replies

3. Shell Programming and Scripting

Script counting instances of software running on a machine

Hello to all @here, as Iīm new to this forum, I will try to start in a easy way for my first post. Iīm not beginner in scripting, but also not a proffessional. So please keep easy, if I donīt understand your explanation at once ;) I donīt mean it in a bad way! Here is the Problem: There were... (2 Replies)
Discussion started by: muogli
2 Replies

4. Shell Programming and Scripting

count and number instances of a character in sed or awk

I currently use LaTeX together with a sed script to set cloze test papers for my students. I currently pepend and equals sign to the front of the words I want to leave out in the finished test, =perpendicular, for example. I am able to number the blanks using a variable in LaTeX. I would like to... (8 Replies)
Discussion started by: maouinin
8 Replies

5. UNIX for Dummies Questions & Answers

Help with counting string elements

Hi All, I hv several files which have hundreds of lines each for example>XYZ.abc01 NNNTCGGTNNNNNCCACACACMYACACACCCACACCCACSCARCAC I'd like to exculde the first line beginning with ">" and then for the rest of the lines get a count for each string element. So for the above example I would like... (8 Replies)
Discussion started by: pawannoel
8 Replies

6. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

7. Shell Programming and Scripting

Replacing string in all instances (both filenames and file contents) in a directory

Hi, I have a set of files stored in a single directory that I use to set parameters for a physics code, and I would like to streamline the process of updating them all when I change a parameter. For instance, if the files are called A2000p300ini, A2000p300sub, A2000p300run, and the text in each... (3 Replies)
Discussion started by: BlueChris
3 Replies

8. Shell Programming and Scripting

Counting string of a variable

Hi, There is a variable f_name, it store some file names. Value of f_name=a.sql b.sql c.sql....... like this. want to count how many file name the var f_name stores. Without using loop is there any command to count that. (5 Replies)
Discussion started by: Dip
5 Replies

9. Shell Programming and Scripting

How to replace all string instances found by find+grep

Hello all Im performing find + grep operation that looks like this : find . -name "*.dsp" | xargs grep -on Project.lib | grep -v ':0' and I like to add to this one liner the possibility to replace the string " Project.lib" that found ( more then once in file ) with "Example.lib" how can I do... (0 Replies)
Discussion started by: umen
0 Replies

10. Shell Programming and Scripting

Counting the max length of string

Hi all, I have a flat file of 1000 rows. I want to check the length of the 5th column. The one having the longest length , I want to set it as DEFINED PARAMETER. So later I can check others with that particular number only. Any ideas ?? (2 Replies)
Discussion started by: ganesh123
2 Replies
Login or Register to Ask a Question