Tag Info

New answers tagged

2

An awk solution: $ awk '{i[$2]+=$1} END{for(x in i){print i[x]" "x}}' file.txt 35 apple 48 grapefruit 57 banana First awk makes an array whose index is the name (banana, apple, grapefruit) and sums up the values in the first column. At the end that array is printed.


0

I'd use perl. #!/usr/bin/perl use strict; use warnings; my %count_of; while ( <> ) { my ( $word) = m/(\w+)/; $count_of{$word}++; } foreach my $word ( sort { $count_of{$a} <=> $count_of{$b} } keys %count_of ) { print "$count_of{$word} $word\n"; } Run it with perl script.pl file1 file2 file3 file4. Alternatively - you probably ...


4

The main problem has already been highlighted by don_crissti in his comment. He determined the file type by running: file koran ... which outputs: ASCII C++ program text, with CRLF, LF line terminators You need to remove the CR (Carriage Return - hex value \x0D) characters which are present at the end of some lines in your input file. This CR is ...



Top 50 recent answers are included