counting lines and showing the output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers counting lines and showing the output
# 8  
Old 08-02-2004
Untested awk..

awk '{a[$1 FS $2]++}END{for(x in a)print x,a[x]}' infile > outfile
# 9  
Old 08-02-2004
Ha ha ...every time I see a thread like this I just wait for Ygor to respond..He's definitely one with Awk!
# 10  
Old 08-03-2004
YGOR your close to the result that i wanted

this is the output of your awk
YRLNCA11-SL1 DMT8a4 13

it should have been
YRLNCA11-SL1 DMT8a4 5 2
YRLNCA11-SL1 DMT8a4 6 11

the first 2 fields are still the same but the 2nd to the last is different - 5 and 6

5 appeared 2x
and 6 appeared 11x

almost there ... but I could still use that awk though..

THANKS
# 11  
Old 08-03-2004
You could probably change Ygor's awk to

awk '{a[$1 FS $2 FS $3]++}END{for(x in a)print x,a[x]}' infile > outfile

to use the first three fields as the index

Cheers
ZB
# 12  
Old 08-03-2004
awk not clear

Please can somebody explain the awk solution of ygor and zazzybob, i tried to play with it on my machine to make some sence of it but it is not clear yet...
i am an awk lover but still biginner.
# 13  
Old 08-03-2004
The awk program uses an associative array "a" to hold the count for each key. The key is the first 2 or 3 fields. At the end of the input file, loop thru the array and print each key with its count.

It's not mandatory to use awk, you could use shell utils, e.g....

$ sort infile | cut -d' ' -f-3 | uniq -c | while read A B C D; do echo $B $C $D $A; done
ALBQNMMA-SL1 DMT8a4 12 1
ALBQNMMA-SL1 DMT8a4 3 4
FUTNCA01-SL1 DMT8a4 5 6
FUTNCA01-SL1 DMT8a4 6 3
# 14  
Old 08-03-2004
THANK YOU TO EVERYBODY THAT HELPED -- LEARNED A LOT!!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pgrep not showing desired output

I am searching for a process that should be up and running. Im using the following command ps -ef | grep elasticsearch to get elastic+ 1673 1 0 Jan29 ? 05:08:56 /bin/java -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

2. Shell Programming and Scripting

Script showing incorrect output

Hello scripting geeks, I am new to scripting and facing some issues in writing the logic of the script. Request your kind help here Actually when i run a command i get o/p as below o/p : 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 these are hex values i guess...now i want to... (15 Replies)
Discussion started by: kulvant29
15 Replies

3. UNIX for Dummies Questions & Answers

Command showing no output!

Hi Folks, I have a situation here, where no command is giving any output, and it's not even showing any error message also. What could be the reason? (3 Replies)
Discussion started by: nixhead
3 Replies

4. Shell Programming and Scripting

Now showing the correct output

Hello I am working on one script where I am trying to display all the directories which is inside the workspace but somehow it is giving me weird output and this is occurring only with one directory other also having the result.html file inside the directory. for i in `ls -1 | egrep -iv... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

5. Solaris

Showing strange size in df output

Hi, This is Solaris-10 box and in few of file-system (root file-system of non global zones), usage/available is not showing correct size. I am not able to figure out, what is eating up this space. Global Server - bdrpod01 Non Global zone - bdrpod01-zputq01 root@bdrpod01:/root# df -h... (2 Replies)
Discussion started by: solaris_1977
2 Replies

6. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

7. UNIX for Dummies Questions & Answers

HELP! showing output as a ratio in uniq

Hi, I have the following file called addresses, (it is a large file i have only copy and pasted few of the data below) and I am wanting to write a command so it will Find the ratio of mobile (07....) to land line (01....) telephone numbers? then find the most popular first name and list the... (1 Reply)
Discussion started by: tina_2010
1 Replies

8. Shell Programming and Scripting

Showing the first 4 lines of a file?

Is there a way to show the first 4 lines of a file without using head -4? In sed would it be sed '1,4d' ? What if I just wanted to display the 2nd line ONLY? How could this be done with AWK?...correctly with SED? (6 Replies)
Discussion started by: puttster
6 Replies

9. Shell Programming and Scripting

Counting lines for each application

Hi All, I have a output that suppose to be like this (see below please) App : Line counts === ================== AAA: 100 BBB: 201 CCC: 137 DDD: 32 EEE: 55 for i in `ps -ef | grep App`; do print $i; done This only shows App : === (12 Replies)
Discussion started by: Beginer0705
12 Replies

10. Shell Programming and Scripting

Help with showing the difference in two lines of input

I would like my script to be able to tell the difference between to lines of input, like: Input 1: 1 2 3 4 5 Input 2: 1 2 3 4 5 6 I want the script to tell me that the difference between the two lines is the 6. Is there anyway I can have it do this? Here's an example of what my script... (12 Replies)
Discussion started by: Kweekwom
12 Replies
Login or Register to Ask a Question