using cut command with sort


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using cut command with sort
# 1  
Old 01-02-2007
using cut command with sort

how to cut for pattern in the file and then count each occurance?

say, each line has unique pattern and u want to grep but at last, you want to see how many of them occur?

say,

cut -d'\" -f15 filename | sort -? or.. do i need to use sed or something..

i need to count lets say

how many larrry were there
how many sarah were there and so on... pleas ehlpe
# 2  
Old 01-02-2007
do_whatever | sort | uniq -c

Cheers
ZB
# 3  
Old 01-02-2007
I got it and that works fine..

now, can you do this in perl?
# 4  
Old 01-03-2007
Quote:
Originally Posted by hankooknara
I got it and that works fine..

now, can you do this in perl?
Code:
#!/usr/bin/perl
        while (<>) {
		chop;
		@F = split /:/;
                $count{$F[6]}++;
        }
        foreach $pattern (sort keys %count) {
                print "$pattern $count{$pattern} \n";
        }

Here : is the field separator and
6 is the field - 1 for which you need the count

Last edited by anbu23; 04-27-2007 at 08:06 AM..
# 5  
Old 01-03-2007
What is this? A test? Why don't YOU do it in perl?
# 6  
Old 01-03-2007
thank you.. and no not a test.. I am using this command at work.. but since I wanted to learn perl and was reading up on it.. wanted to know how to accomplish this in perl.. just wanted to see the gist of it.. but thank you all. You been great help.. and next time, I promise I will write perl myself
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. UNIX for Advanced & Expert Users

cut and sort

Please help. I have a file containing rows of information. The row needs to be broken down into blocks of 5 and then sorted. Example: 10381 1042010046 ... (4 Replies)
Discussion started by: Dolph
4 Replies

3. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

4. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

5. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

6. Homework & Coursework Questions

Help with cut and sort

<B>andan100:Anders:Andersson:800101-1234:TNCCC_1:TDDB46 TDDB80:berbe101:Bertil:Bertilsson:800102-1234:TNCCC_1:TDDB46 TDDB80:The top is how it looks right now I want it t look like this under and I want it to be sorted. I have tried with cut -f -d studenter.txt and so on but it still doesnt work... (2 Replies)
Discussion started by: aannaann
2 Replies

7. UNIX for Dummies Questions & Answers

Using the Sort, Cut, and Awk commands

Hello, I am trying, utilizing the few commands I know, to extract all records within my file that were generated in November of 2007. Each record within the file has a "date" field giving the month, day, and year (9-8-88). How do I extract those records to their own file? Once I extract... (4 Replies)
Discussion started by: babbabooey
4 Replies

8. Solaris

concatenate/sort/cut

I have the following requirement. 1. I have to concatenate the 10 fixed width files. 2. sort based on first 10 characters 3. after that i have remove first 10 chacters from the file. can you please tell me how to do it. Thanks in Advance Samba (1 Reply)
Discussion started by: samba
1 Replies

9. Shell Programming and Scripting

sort / cut question

Hi All, I have a small problem, hope you can help me out here. I have a file that contains the same format of lines in 99% of the cases. 906516 XYZ.NNN V 0000 20070711164648 userID1 userID2 hostname 20070711164641 There are unfortunately several lines with these... (5 Replies)
Discussion started by: BearCheese
5 Replies

10. UNIX for Dummies Questions & Answers

Help with Last,uniq, sort and cut

Using the last, uniq, sort and cut commands, determine how many times the different users have logged in. I know how to use the last command and cut command... i came up with last | cut -f1 -d" " | uniq i dont know if this is right, can someone please help me... thanks (1 Reply)
Discussion started by: jay1228
1 Replies
Login or Register to Ask a Question