Hi all,
I have a quick question:
I have a 4 column tab-separated file.
I want to count the number of times each unique value in column 2 appears and add that number in a 5th column.
I have the following input file:
Code:
waterline-n below-sheath-v 14.8097 A
dock-n below-sheath-v 14.5095 B
waterline-n below-steel-n 11.0330 A
picnic-n below-steel-n 12.2277 C
wavefront-n at-part-of-variance-n 18.4888 L
wavefront-n between-part-of-variance-n 17.0656 A
audience-b between-part-of-variance-n 17.6346 B
game-n between-part-of-variance-n 14.9652 C
whereabouts-n become-rediscovery-n 11.3556 L
whereabouts-n get-tee-n 10.9091 L
and the following is the desired output
Code:
waterline-n below-sheath-v 14.8097 A 2
dock-n below-sheath-v 14.5095 B 2
waterline-n below-steel-n 11.0330 A 2
picnic-n below-steel-n 12.2277 C 2
wavefront-n at-part-of-variance-n 18.4888 L 1
wavefront-n between-part-of-variance-n 17.0656 A 3
audience-b between-part-of-variance-n 17.6346 B 3
game-n between-part-of-variance-n 14.9652 C 3
whereabouts-n become-rediscovery-n 11.3556 L 1
whereabouts-n get-tee-n 10.9091 L 1
How can I combine sort and grep for the desired output?
Thank you.
I just realized that your script counts all of the unique instances in Column 2.
However, I need to count the number of different items in Column 4 that a value in Column 2 occurs with in --- in this case, real frequency does not matter.
I will provide more sample files, in case my question was not clear:
For instance this input file:
Code:
waterline-n below-sheath-v 14.8097 A
dock-n below-sheath-v 14.5095 B
waterline-n below-steel-n 11.0330 A
picnic-n below-steel-n 12.2277 C
game-n below-steel-n 12.2277 D
dock-n below-steel-n 12.2277 D
wavefront-n at-part-of-variance-n 18.4888 L
wavefront-n between-part-of-variance-n 17.0656 A
audience-b between-part-of-variance-n 17.6346 B
game-n between-part-of-variance-n 14.9652 C
whereabouts-n become-rediscovery-n 11.3556 L
whereabouts-n get-tee-n 10.9091 L
should yield this output file:
Code:
waterline-n below-sheath-v 14.8097 A 2
dock-n below-sheath-v 14.5095 B 2
waterline-n below-steel-n 11.0330 A 3
picnic-n below-steel-n 12.2277 C 3
game-n below-steel-n 12.2277 D 3
dock-n below-steel-n 12.2277 D 3
wavefront-n at-part-of-variance-n 18.4888 L 1
wavefront-n between-part-of-variance-n 17.0656 A 3
audience-b between-part-of-variance-n 17.6346 B 3
game-n between-part-of-variance-n 14.9652 C 3
whereabouts-n become-rediscovery-n 11.3556 L 1
whereabouts-n get-tee-n 10.9091 L 1
Where "below-steal-n" acutally occurs 4 times --- yet with 3 different items in Column 4 --- thus, in Column 5 its result is 3.
Last edited by owwow14; 10-31-2013 at 02:08 PM..
Reason: FIXED ERROR
Not sure if your sample output is correct based on your description: the 'between-part-of-variance-n' fields are not counted correctly.
Pls validate/clarify
I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file.
Here is the file.
<!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
I'm pretty new to scripting and didn't see an example of this issue yet. I am trying to count and print the total number of times each value is found within a file. Here is a short example of my starting file.
value 3
value 3
value 3
value 3
value 4
value 6
value 6
value 6
value 6... (3 Replies)
Hi,
I need a shell script which can provide details from error logs like this
Aug 23 21:19:41 red mountd: authenticated mount request from bl0110.bang.m
pc.local:651 for /disk1/jobs (/disk1)
Aug 23 08:49:52 red dhcpd: DHCPDISCOVER from 00:25:90:2b:cd:7c via eth0: unknown client
Aug 24... (2 Replies)
Dear UNIX community,
I would like to to count characters from a specific row and have them displayed line-by-line.
I have a file called testAwk2.csv which contain the following data:
rabbit penguin goat
giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Hello all
siteexplorer.search.yahoo.com can output results in tsv format, when opened in excel I get 4 columns.
I would like to wget that file, which I can do. I would then like to pull the 2nd column and output it only.
I've searched around and found a few bits and pieces but nothing I've... (6 Replies)
Hi,
I've been trying to create a perl file to run something very specific. But I'm not getting any success. I'm not very good with hashing.
I have a file with two columns (tab separated) (already sorted)
99890 +
100281 +
104919 -
109672 +
113428 -
114501 +
115357 +
115598 ... (7 Replies)
Hi,
Can someone help me count this line:
Say I have a file (file1.txt) that contains below:
11/16 13:08:19.5436 18096 --- Generating a <reading> event
11/16 13:08:19.7784 18096 ---- Sending a <writing> event
11/16 13:08:37.4516 18096 --- Generating a <reading> event
11/16... (1 Reply)
Hi,
I need to count the number of occurences of the character " in a file that contains huge number of records.
What command could I use?
Please specify in detail since I am new :|
Thanks much. (3 Replies)