problem with the script in counting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with the script in counting
# 1  
Old 04-06-2008
Bug problem with the script in counting

Hi,

I have a script which greps for a word in a file contains records.
I grabbed a particular column & sent the colomn values to a file.
I need to find each column value, the times it appeared in the file.
My script is:
grep sceneority <file> | cut -f 6 >> swi

With above I grabbed the 6 th column and sent to swi file
I am stuck at how to find the occurance of column values in "swi" file.
Plz help me.
Ex:

The file has following column values:

123
324
123
123
435
435

The output should be

123 is 3 times
324 is 1 time
435 is 2 times

Thanks & Regards,
Pradeep.
# 2  
Old 04-06-2008
Code:
sort file | uniq -c | sort -rn

This is pretty much the "hello world" of shell scripts.
# 3  
Old 04-06-2008
problem with the script in counting

Hi Thanks for the reply.

I have one more doubt.
If I grabbed 2 or more fileds to the file and and If I want to count on only one more field...how the sort should be....
for example,

grep sceneority <file> | cut -f 3,4,6 >> swi
I want to count on only 6th field....
# 4  
Old 04-06-2008
Some extended versions of uniq have a flag to skip over some fields. In the general case, though, either write a simple awk script (if you need to keep the file intact, and somehow add this frequency count information) or just cut the field you want to count and proceed as previously.

In your new swi file, the former field 6 is field 3, obviously.

Code:
cut -f3 swi | sort | uniq -c | sort -rn

# 5  
Old 04-06-2008
Without the use of the temporary file swi, grep, cut, sort and uniq:

Code:
awk '/sceneority/{a[$6]++}END{for(i in a){print i, a[i]}}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Error in script while counting processes

Hi all, Below is a script I'm writing and giving me error: #!/usr/bin/sh if ; then echo "Success!" else echo "Failure!" fi Normally if I do ps -ef|grep dw.sap|wc -l it gives me output of 18. So my script checks if it's greater than 17 it echoes success else failure ... (5 Replies)
Discussion started by: frum
5 Replies

2. Shell Programming and Scripting

Word counting perl script

Hi friends i need a help on Perl Script In My Home directory, i have some other directories and inside those directories i have some subdirectories and all the directories contains files. Now i want to count a word in all files and i want the output like below wordcount in which file(name... (5 Replies)
Discussion started by: siva kumar
5 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

counting the number of visitor to script

I need to write script, counting the number of visitor to this script. help me please! Code tags for code, please. (1 Reply)
Discussion started by: numeracy
1 Replies

5. Shell Programming and Scripting

Problem counting unique disks/slices

I want to create a unique listing of slices/disks from a large list that will have duplicates. Here is a sample of the input file. #array.txt Disk4:\s93 Disk4:\s93 Disk4:\s94 Disk4:\s95\s96\s97 Disk4:\s93 Disk4:\s95\s96\s103 Disk4:\s93 Disk4:\s93 Disk4:\s95\s96\s105 Disk4:\s93... (5 Replies)
Discussion started by: jontjioe
5 Replies

6. UNIX for Advanced & Expert Users

Problem while counting number of fields in TAB delimited file

I'm facing a strange problem, please help me out. Here we go. I want to count number of fields in particular file. filename and delimiter character will be passed through parameter. On command prompt if i type following i get 27 as output (which is correct) cat customer.dat | head -1 | awk... (12 Replies)
Discussion started by: vikanna
12 Replies

7. Shell Programming and Scripting

Counting script how many times it run?

i should use this script runs how many times before ? how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies

8. UNIX for Dummies Questions & Answers

grep -c script counting string twice instead of once?

I tried this script to get a count of the occurrence of a string in files. I have multiple files in one directory I will use this on. All the filenames begin "invALL.06" The script works, except it counts twice for every one instance of 'Invoice Total'. If there are 5 occurences of 'Invoice... (2 Replies)
Discussion started by: scarletsupra
2 Replies

9. Shell Programming and Scripting

Help me streamline this counting part of my script.

Ok, so this is a small part of a script I wrote to build disk groups using VXVM. The only problem is that I am limited to a count of 8 maximum. If I want more, I will have to add more lines of "if" statements. How can I accomplish the same thing, in a few lines, but not be limited in the max... (13 Replies)
Discussion started by: LinuxRacr
13 Replies

10. Shell Programming and Scripting

counting in shell script

hi i am writing a korn shell script to compile all programs there are arount 2000+ files now i have a script that can compile programs but i want to show status of compilation because to compile all programs it takes around 10-15 mins so how can i display status like it should print no of files... (3 Replies)
Discussion started by: zedex
3 Replies
Login or Register to Ask a Question