Sponsored Content
Full Discussion: [awk] Compare two files
Top Forums Shell Programming and Scripting [awk] Compare two files Post 302948663 by RudiC on Wednesday 1st of July 2015 10:18:53 AM
Old 07-01-2015
How about
Code:
awk '
        {for (i=1; i<=length; i++)
                {aux=tolower(substr($0,i,1))
                 if ( aux != " " && aux != "" )
                        letter[FILENAME,aux]++
                        if ( letter[FILENAME,aux] > max[FILENAME] )
                                {max[FILENAME]=letter[FILENAME,aux]
                                 max_letter[FILENAME]=aux
                                }
                }
        }
END     {for (F in max) {print "Lettera maggiormente utilizzata in " F ": " max_letter[F] ", Occorrenze:" max[F]
                         for (item in letter)  if (item ~ F)
                                {split (item, T, SUBSEP)
                                 print "Lettera:" T[2] ", Occorrenze: " letter[item], F | "sort"
                                }
                         close ("sort")
                        }
        }
' file[12]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk compare 2 files

Hi i hope some awk gurus here can help me.. here is what i need i have 2 files: File1 152445 516532 405088.pdf 152445 516533 405089.pdf 152491 516668 405153.jpg 152491 520977 408779.jpg 152491 0 409265.pdf File2 516532 /tmp/MainStreet_Sum09_Front_FNL.pdf 516533... (9 Replies)
Discussion started by: kenray
9 Replies

2. Shell Programming and Scripting

Compare two files using awk

Hi. I'm new to awk and have searched for a solution to my problem, but haven't found the right answer yet. I have two files that look like this: file1 Delete,3105551234 Delete,3105551236 Delete,5625559876 Delete,5625556789 Delete,5625553456 Delete,5625551234 Delete,5625556956... (8 Replies)
Discussion started by: paul.o
8 Replies

3. Shell Programming and Scripting

compare two files using awk

Hi, I want to compare two files using awk and write an output based on if the records matched. Both the files are space delimitted. File A: 8351 00000000000636 2009044 -00001.000 8351 00000000000637 2009044 -00002.000 8351 00000000000638 2009044 -00001.000 8351 00000000000640... (7 Replies)
Discussion started by: gpaulose
7 Replies

4. UNIX for Dummies Questions & Answers

Using AWK to compare 2 files

Hi How can I use awk to compare specific columns in 2 files and print the difference. I currently have this: BEGIN { OFS = FS = "," } NR == FNR { b = $3 next } { e = "" for (x in b) { if (match ($1, x)) { if (RSTART == 1 && RLENGTH > length(e)) { e=x (2 Replies)
Discussion started by: ladyAnne
2 Replies

5. Shell Programming and Scripting

Compare two files with awk

Hello, I have a script which extracts the values from a csv file when a specific date is entered : #!/bin/sh awk 'BEGIN{printf("Entrez la date : "); getline date < "-"} $0 ~ date {f=1;print;next} /^{2}\//{f=0} f' file1.csv This script gives me a number of lines with different values. ... (6 Replies)
Discussion started by: freyr
6 Replies

6. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

7. Shell Programming and Scripting

Compare files using awk

Please help me to compare two files and remove the items in file2 from file1 file 1:delimited using pipe(|) file1 00012|Description - 1|||||AA12345|1|AB12345|2|2012/06/03 AB123|Description - 2|||||AA12345|3|ZA11111|4|2012/06/04 11111|Description - 3|||||AP00012|1|AB12345|2|2012/06/03... (8 Replies)
Discussion started by: Mary James
8 Replies

8. HP-UX

Awk compare two files

Hi guys, I have 2 files: File1 ABC|2203|115.50 ABC|2288|328.12 ABC|2289|611.09 ABC|2290|698 DEF|1513|721.3 DEF|1514|40 DEF|1515|5 File2 ABC|2288|328.12 ABC|2289|666.08 ABC|2290|698.00 DEF|1513|721.30 (3 Replies)
Discussion started by: Eduardo Aceves
3 Replies

9. Shell Programming and Scripting

Compare 2 files, awk maybe?

I have 2 files, file1: alfa numbers numbers vita numbers numbers gama numbers numbers delta numbers numbers epsilon numbers numbers zita numbers numbers ... file2: 'zita' keepnumbers keepnumbers keepnumbers 'gama' keepnumbers keepnumbers keepnumbers 'misc' ... (11 Replies)
Discussion started by: phaethon
11 Replies

10. Shell Programming and Scripting

awk compare files

I have a below requirement and trying to compare the files using awk File 1 - Already stored on a prev day id | text | email id --------------------------------- 89564|this is line 1 | xyz@sample.txt 985384|this is line 2 | abc@sample.txt 657342|this is line 3 |... (3 Replies)
Discussion started by: rakesh_411
3 Replies
Gedcom::Item(3pm)					User Contributed Perl Documentation					 Gedcom::Item(3pm)

NAME
Gedcom::Item - a base class for Gedcom::Grammar and Gedcom::Record Version 1.16 - 24th April 2009 SYNOPSIS
use Gedcom::Record; $item->{grammar} = Gedcom::Grammar->new(file => $item->{grammar_file}, callback => $item->{callback}); my $c = $item->copy; $item->read if $item->{file}; $item->add_items($rec); while (my $next = $item->next_item($item)) my $line = $item->next_line; my $line = $item->next_text_line; $item->write($fh, $level, $flush); $item->write_xml($fh, $level); $item->print; my $item = $item->get_item("CHIL", 2); my @items = $item->get_item("CHIL"); my $parent = $item->parent; my $success = $item->delete; $item->delete_item($sub_item); my $v = $item->level; $item->level(1); my $v = $item->xref; my $v = $item->tag; my $v = $item->value; my $v = $item->pointer; my $v = $item->min; my $v = $item->max; my $v = $item->gedcom; my $v = $item->file; my $v = $item->line; my $v = $item->full_value; my $sub_items = $item->_items; my @sub_items = $item->items; $item->delete_items; DESCRIPTION
A selection of subroutines to handle items in a gedcom file. HASH MEMBERS
Some of the more important hash members are: $item->{level} The level of the item. $item->{xref} The cross reference, either hard or soft. $item->{tag} The name of the tag. $item->{value} The value of the item. $item->{pointer} True iff the value is a pointer to another item. $item->{min} The minimum number of items allowed. $item->{max} The maximum number of items allowed. $item->{gedcom} The top level gedcom object. $item->{file} The file from which this object was read, if any. $item->{line} The line number from which this object was read, if any. $item->{items} Array of all sub-items of this item. It should not be necessary to access these hash members directly. METHODS
new $item->{grammar} = Gedcom::Grammar->new(file => $item->{grammar_file}, callback => $item->{callback}); Create a new object. If file is supplied, it is the name of a file to read. If callback is supplied, it is a subroutine reference which is called at various times while the file is being read. The subroutine takes five parameters: $title: A title $txt1: One text message $txt2: A secondary text message $current: A count of how far through the file we are $total: The extent of the file The subroutine should return true iff the file shuld continue to be read. copy my $c = $item->copy; Make a copy of the object. The sub-items are copied too. read $item->read if $item->{file}; Read a file into the object. Called by the constructor. add_items $item->add_items($rec); Read in the sub-items of a item. next_item while (my $next = $item->next_item($item)) Read the next item from a file. Return the item or false if it cannot be read. next_line my $line = $item->next_line; Read the next line from the file, and return it or false. next_text_line my $line = $item->next_text_line; Read the next line of text from the file, and return it or false. write $item->write($fh, $level, $flush); Write the item to a FileHandle. The subroutine takes three parameters: $fh: The FileHandle to which to write $level: The level of the item $flush: Whether or not to indent the gedcom output according to the level write_xml $item->write_xml($fh, $level); Write the item to a FileHandle as XML. The subroutine takes two parameters: $fh: The FileHandle to which to write $level: The level of the item Note that this function is experimental. Please read the warnings for Gedcom::write_xml(). print $item->print; Print the item. Used for debugging. (What? There are bugs?) get_item my $item = $item->get_item("CHIL", 2); my @items = $item->get_items("CHIL"); Get specific sub-items from the item. The arguments are the name of the tag, and optionally the count. In scalar context, returns the sub-item, or undef if it doesn't exist. In array context, returns all sub-items matching the specified tag. get_child NOTE - This function is deprecated - use get_item instead my $child = get_child("CHIL2"); Get a specific child item from the item. The argument contains the name of the tag, and optionally the count. The regular expression to generate the tag and the count is: my ($tag, $count) = $t =~ /^_?(w+?)(d*)$/ Returns the child item, or undef if it doesn't exist get_children NOTE - This function is deprecated - use get_item instead my @children = get_children("CHIL"); parent my $parent = $item->parent; Returns the parent of the item or undef if there is none. Note that this is an expensive function. A child does not know who its parent is, and so this function searches through all items looking for one with the appropriate child. delete my $success = $item->delete; Deletes the item. Note that this is an expensive function. It use parent() described above. It is better to use $parent->delete_item($child), assuming that you know $parent. Note too that this function calls delete_item(), so its caveats apply. delete_item $item->delete_item($sub_item); Delete the specified sub-item from the item. Note that this function doesn't do any housekeeping. It is up to you to ensure that you don't leave any dangling pointers. Access functions my $v = $item->level; $item->level(1); my $v = $item->xref; my $v = $item->tag; my $v = $item->value; my $v = $item->pointer; my $v = $item->min; my $v = $item->max; my $v = $item->gedcom; my $v = $item->file; my $v = $item->line; Return the eponymous hash element. If a value if passed into the function, the element is first assigned that value. full_value my $v = $item->full_value; Return the value of the item including all CONT and CONC lines. This is probably what you want most of the time, and is the function called by default from other functions that return values. If, for some reason, you want to process CONT and CONC items yourself, you will need to use the value() function and probably the items() function. _items my $sub_items = $item->_items; Return a reference to alist of all the sub-items, reading them from the Gedcom file if they have not already been read. It should not be necessary to use this function. See items(). items my @sub_items = $item->items; Return a list of all the sub-items, reading them from the Gedcom file if they have not already been read. In general it should not be necessary to use this function. The sub-items will usually be accessed by name. This function is only necessary if the ordering of the different items is important. This is very rare, but is needed for example, when processing CONT and CONC items. delete_items $item->delete_items; Delete all the sub-items, allowing the memory to be reused. If the sub-items are required again, they will be reread. It should not be necessary to use this function unless you are using read_only mode and need to reclaim your memory. perl v5.14.2 2012-04-12 Gedcom::Item(3pm)
All times are GMT -4. The time now is 10:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy