Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sorting using count, grep and count Post 302209420 by shamrock on Friday 27th of June 2008 12:13:12 AM
Old 06-27-2008
Question Output

Show how the output should look like for a given input sample.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies

2. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

3. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

4. Shell Programming and Scripting

Uniq sorting and count

Hi Unix gurus, I have a requirement where I need to find the file count based on unique file names. OPEN_INV_MMDDYYYY_HHMM.xls OPEN_INV_MMDDYYYY_HHMM.xls OPEN_INV_MMDDYYYY_HHMM.xls CLOSE_INV_MMDDYYYY_HHMM.xls CLOSE_INV_MMDDYYYY_HHMM.xls OPEN_INV_MMDDYYYY_HHMM.txt... (2 Replies)
Discussion started by: shankar1dada
2 Replies

5. Shell Programming and Scripting

Sorting user by last login an count

Experts need your help i need to create a script which will give count of users logged between yesterday and today (Or if run exacle 12:00AM midnight, it will give count of of users logged on that day here is how the data looks Pappu, Paul|22-Feb-201|0|30-Jun-201 Aloor,... (9 Replies)
Discussion started by: karghum
9 Replies

6. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

7. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

8. Shell Programming and Scripting

Count occurences of a character in a file by sorting results

Hello, I try to sort results of occurences in an array by using awk but I can't find the right command. that's why I'm asking your help ! :) Please see below the command that I run: awk '{ for ( i=1; i<=length; i++ ) arr++ }END{ for ( i in arr ) { print i, arr } }' dictionnary.txt ... (3 Replies)
Discussion started by: destin45
3 Replies

9. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies
MouseX::NativeTraits::ArrayRef(3pm)			User Contributed Perl Documentation		       MouseX::NativeTraits::ArrayRef(3pm)

NAME
MouseX::NativeTraits::ArrayRef - Helper trait for ArrayRef attributes SYNOPSIS
package Stuff; use Mouse; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); DESCRIPTION
This module provides an Array attribute which provides a number of array operations. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::ArrayRef. count Returns the number of elements in the array. $stuff = Stuff->new; $stuff->options(["foo", "bar", "baz", "boo"]); my $count = $stuff->count_options; print "$count "; # prints 4 is_empty Returns a boolean value that is true when the array has no elements. $stuff->has_no_options ? die "No options! " : print "Good boy. "; elements Returns all of the elements of the array. my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" get($index) Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. my $option = $stuff->get_option(1); print "$option "; # prints "bar" pop push($value1, $value2, value3 ...) shift unshift($value1, $value2, value3 ...) splice($offset, $length, @values) These methods are all equivalent to the Perl core functions of the same name. first( sub { ... } ) This method returns the first item matching item in the array, just like List::Util's "first" function. The matching is done with a subroutine reference you pass to this method. The reference will be called against each element in the array until one matches or all elements have been checked. my $found = $stuff->find_option( sub { /^b/ } ); print "$found "; # prints "bar" any( sub { ... } ) This method returns true if any item in the array meets the criterion given through the subroutine, otherwise returns false. It sets $_ for each item in the array. grep( sub { ... } ) This method returns every element matching a given criteria, just like Perl's core "grep" function. This method requires a subroutine which implements the matching logic. my @found = $stuff->filter_options( sub { /^b/ } ); print "@found "; # prints "bar baz boo" map( sub { ... } ) This method transforms every element in the array and returns a new array, just like Perl's core "map" function. This method requires a subroutine which implements the transformation. my @mod_options = $stuff->map_options( sub { $_ . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" apply( sub { ... } ) This method also transform every element in the array and returns a new array, just like List::MoreUtils's "apply" function.his is similar to "map", but does not modify the element of the array. reduce( sub { ... } ) This method condenses an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's "reduce" function. The reducing is done with a subroutine reference you pass to this method. my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } ); print "$found "; # prints "foobarbazboo" sort( &compare ) Returns the array in sorted order. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" sort_in_place( &compare ) Sorts the array in place, modifying the value of the attribute. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. sort_by( &by, &compare ) Returns the array in sorted order, applying &by function to each item. This is equivalent to "sort(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. sort_in_place_by( &by, &compare ) Sorts the array, applying &by function to each item, modifying the value of the attribute. This is equivalent to "sort_in_place(sub{ by($_[0]) cmp by($_[1]) })", but implemented effectively. Currently (as of Moose 0.98) this is a Mouse specific method. shuffle Returns the array, with indices in random order, like "shuffle" from List::Util. uniq Returns the array, with all duplicate elements removed, like "uniq" from List::MoreUtils. join($str) Joins every element of the array using the separator given as argument, just like Perl's core "join" function. my $joined = $stuff->join_options( ':' ); print "$joined "; # prints "foo:bar:baz:boo" set($index, $value) Given an index and a value, sets the specified array element's value. delete($index) Removes the element at the given index from the array. insert($index, $value) Inserts a new element into the array at the given index. clear Empties the entire array, like "@array = ()". accessor This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. for_each(sub{ ... }) This method calls the given subroutine with each element of the array, like Perl's core "foreach" statement. Currently (as of Moose 0.98) this is a Mouse specific method. for_each_pair( sub{ ... } ) This method calls the given subroutine with each two element of the array, as if the array is a list of pairs. Currently (as of Moose 0.98) this is a Mouse specific method. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits perl v5.14.2 2011-12-04 MouseX::NativeTraits::ArrayRef(3pm)
All times are GMT -4. The time now is 05:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy