07-30-2009
yes, I got an error message "Useless use of hash element in void context ....filename...
Thanx.
---------- Post updated at 02:40 PM ---------- Previous update was at 02:20 PM ----------
I've made changes to the code to handle utf8 as :--
use encoding 'utf8';
my %unique;
# my $unique;
my $line;
open my $FH, "<:encoding(utf8)", "$ARGV[0]" or die "Can't open file $ARGV[0]: $!";
while(<$FH>) {
chomp;
$unique{$_}++;
}
close $FH;
foreach my $line (keys %unique) {
print "$line = $unique{$line}\n";
}
However, I am getting the message....
2 files to edit.
I don't know this.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I need to grep for a pattern in a file. Files are huge and have several repeated occurances of the strings which match pattern. I just need the strings which contain the pattern in the output.
For eg.
The contents of my file are as follows. The pattern I want to match by is ABCD
... (5 Replies)
Discussion started by: tektips
5 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
Hello Guys
I have a flat file with '|~|' delimited
When I use to record count using below command
awk -FS"+" ' {print $colno}' filename | wc -l
the count is fine
But when I am trying to find the unique number of record the o/p is always 1
awk -FS"+" ' {print $colno}'... (11 Replies)
Discussion started by: Pratik4891
11 Replies
4. Shell Programming and Scripting
Hi,
Im looking for a script which will calculate the unique strings column 2 & 3 values in a log as mentioned in example
eg:-
bag 12 12
bag 18 15
bags 15 13
bags 15 14
blazer 24 24
blazer 33 32
boots 19 15
Result should be:-
bag 30 27
bags 30 27... (9 Replies)
Discussion started by: Paulwintech
9 Replies
5. Shell Programming and Scripting
how to display the unique strings in two files using shell script or commands.
I tried diff and cmp but it shows the entire line, i need only the mismatched strings.
File1:
sat,sun,mon,tue
rose,lilly,lotus
white,red,blue,green,pink
File2:
sat,sun,mon,tue
rose,sunflower,lotus... (4 Replies)
Discussion started by: Arun_Linux
4 Replies
6. Shell Programming and Scripting
Im looking for an awk script that will take the unique values in column 5, then print and count the unique values in column 6.
CA001011500 11111 11111 -9999 201301 AAA
CA001012040 11111 11111 -9999 201301 AAA
CA001012573 11111 11111 -9999 201301 BBB
CA001012710 11111 11111 -9999 201301... (4 Replies)
Discussion started by: ncwxpanther
4 Replies
7. Shell Programming and Scripting
When I use the below awk to count the unique lines in $4 for the input it seems to work. The answer is 3 because $4 is only unique 3 times in all the entries. However, when I use the same on actual data I get 56,536 and I know the answer should be 56,548. My question is there a better way to... (8 Replies)
Discussion started by: cmccabe
8 Replies
8. Shell Programming and Scripting
Hello Team,
I need your help on the following:
My input file a.txt is as below:
3330690|373846|108471
3330690|373846|108471
0640829|459725|100001
0640829|459725|100001
3330690|373847|108471
Here row 1 and row 2 of column 1 are identical but corresponding column 2 value are... (4 Replies)
Discussion started by: angshuman
4 Replies
9. UNIX for Beginners Questions & Answers
Dear all,
I would like to know how to list and count unique words in thousands number of text files.
Please help me out
thanks in advance (9 Replies)
Discussion started by: imranrasheedamu
9 Replies
10. UNIX for Beginners Questions & Answers
Hello,
I am trying to count unique rows in my file based on 4 columns (2-5) and to output its frequency in a sixth column. My file is tab delimited
My input file looks like this:
Colum1 Colum2 Colum3 Colum4 Coulmn5
1.1 100 100 a b
1.1 100 100 a c
1.2 200 205 a d
1.3 300 301 a y
1.3 300... (6 Replies)
Discussion started by: nans
6 Replies
LEARN ABOUT CENTOS
encode::encoder
Encode::Encoder(3) User Contributed Perl Documentation Encode::Encoder(3)
NAME
Encode::Encoder -- Object Oriented Encoder
SYNOPSIS
use Encode::Encoder;
# Encode::encode("ISO-8859-1", $data);
Encode::Encoder->new($data)->iso_8859_1; # OOP way
# shortcut
use Encode::Encoder qw(encoder);
encoder($data)->iso_8859_1;
# you can stack them!
encoder($data)->iso_8859_1->base64; # provided base64() is defined
# you can use it as a decoder as well
encoder($base64)->bytes('base64')->latin1;
# stringified
print encoder($data)->utf8->latin1; # prints the string in latin1
# numified
encoder("x{abcd}x{ef}g")->utf8 == 6; # true. bytes::length($data)
ABSTRACT
Encode::Encoder allows you to use Encode in an object-oriented style. This is not only more intuitive than a functional approach, but also
handier when you want to stack encodings. Suppose you want your UTF-8 string converted to Latin1 then Base64: you can simply say
my $base64 = encoder($utf8)->latin1->base64;
instead of
my $latin1 = encode("latin1", $utf8);
my $base64 = encode_base64($utf8);
or the lazier and more convoluted
my $base64 = encode_base64(encode("latin1", $utf8));
Description
Here is how to use this module.
o There are at least two instance variables stored in a hash reference, {data} and {encoding}.
o When there is no method, it takes the method name as the name of the encoding and encodes the instance data with encoding. If
successful, the instance encoding is set accordingly.
o You can retrieve the result via ->data but usually you don't have to because the stringify operator ("") is overridden to do exactly
that.
Predefined Methods
This module predefines the methods below:
$e = Encode::Encoder->new([$data, $encoding]);
returns an encoder object. Its data is initialized with $data if present, and its encoding is set to $encoding if present.
When $encoding is omitted, it defaults to utf8 if $data is already in utf8 or "" (empty string) otherwise.
encoder()
is an alias of Encode::Encoder->new(). This one is exported on demand.
$e->data([$data])
When $data is present, sets the instance data to $data and returns the object itself. Otherwise, the current instance data is
returned.
$e->encoding([$encoding])
When $encoding is present, sets the instance encoding to $encoding and returns the object itself. Otherwise, the current instance
encoding is returned.
$e->bytes([$encoding])
decodes instance data from $encoding, or the instance encoding if omitted. If the conversion is successful, the instance encoding will
be set to "".
The name bytes was deliberately picked to avoid namespace tainting -- this module may be used as a base class so method names that
appear in Encode::Encoding are avoided.
Example: base64 transcoder
This module is designed to work with Encode::Encoding. To make the Base64 transcoder example above really work, you could write a module
like this:
package Encode::Base64;
use base 'Encode::Encoding';
__PACKAGE__->Define('base64');
use MIME::Base64;
sub encode{
my ($obj, $data) = @_;
return encode_base64($data);
}
sub decode{
my ($obj, $data) = @_;
return decode_base64($data);
}
1;
__END__
And your caller module would be something like this:
use Encode::Encoder;
use Encode::Base64;
# now you can really do the following
encoder($data)->iso_8859_1->base64;
encoder($base64)->bytes('base64')->latin1;
Operator Overloading
This module overloads two operators, stringify ("") and numify (0+).
Stringify dumps the data inside the object.
Numify returns the number of bytes in the instance data.
They come in handy when you want to print or find the size of data.
SEE ALSO
Encode, Encode::Encoding
perl v5.16.3 2013-04-29 Encode::Encoder(3)