Sponsored Content
Top Forums Shell Programming and Scripting Sed/awk to tell differences between two lists Post 303038049 by rdrtx1 on Thursday 22nd of August 2019 12:43:10 PM
Old 08-22-2019
Code:
awk '
{files[FILENAME]; list[$0]; items[$0, FILENAME]=$0;}
END {
for (file in files) printf "%-15s", file FS;
print "";
for (item in list) {
for (file in files) printf "%-15s", items[item, file] FS;
print "";
}
}' list*


Last edited by rdrtx1; 02-18-2020 at 08:27 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Differences in awk between UNIX flavours

Hi, I've been charged with the task of finding out whether the scripts which we use on our current DYNIX (Sequent) UNIX box will continue to run happily on our soon-to-be-installed Sun Solaris box. I'm fairly certain that they'll be OK, but I've heard mutterings about awk running differently... (2 Replies)
Discussion started by: pbritta
2 Replies

2. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

3. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

4. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

5. Shell Programming and Scripting

awk to compare 2nd and 3rd field and print the differences

need a one liner to compare 2nd and 3rd field and print values that are not matched in 2nd field Input col 2 col 3 1.1.1.1 11.11.11.11 8.8.8.8 0.0.0.0 3.3.3.3 2.2.2.2 7.7.7.7 3.3.3.3 5.5.5.5 1.1.1.1 4.4.4.4 6.6.6.6 9.9.9.9 output 7.7.7.7 ... (12 Replies)
Discussion started by: chidori
12 Replies

6. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

7. UNIX for Dummies Questions & Answers

Lists in awk

Hi togehter! I would like to write an awk script which prints the first column divided by the sum of the second column: So if this is my list 1 2 2 1 3 1 4 1 it should print a list like this: 1/5 2/5 3/5 4/5 My idea was to use END like this: (3 Replies)
Discussion started by: bjoern456
3 Replies

8. Shell Programming and Scripting

2 lists, show differences plus or minus

Not really sure how to accomplish this. If I have two lists with matching columns. Second column is different. I would like to show the differences plus/minus. list1 device1 5 decive2 10 decive3 10 device4 10 device5 10 device6 20 list2 device1 10 ... (1 Reply)
Discussion started by: mrlayance
1 Replies

9. Shell Programming and Scripting

awk to find differences between two file

I am trying to find the differences between the two sorted, tab separated, attached files. Thank you :). In update2 there are 52,058 lines and in current2 there are 52,197 so 139 differences should result. However, awk 'FNR==NR{a;next}!($0 in a)' update2 current2 > out2comm -1 -3... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

ksh / AIX - Differences between lists to a text file

This seems pretty simple, but I cant figure it out. I get stumped on the simple things. I am running two commands 1) take a listing a directory of files, and filter out the doc_name (which is in a series of extracted files), and place it in a file. ls -l | awk '{print $9}' | grep... (5 Replies)
Discussion started by: jeffs42885
5 Replies
Prima::IniFile(3)					User Contributed Perl Documentation					 Prima::IniFile(3)

NAME
Prima::IniFile - support of Windows-like initialization files DESCRIPTION
The module contains a class, that provides mapping of text initialization file to a two-level hash structure. The first level is called sections, which groups the second level hashes, called items. Sections must have unique keys. The items hashes values are arrays of text strings. The methods, operated on these arrays are get_values, set_values, add_values and replace_values. SYNOPSIS
use Prima::IniFile; my $ini = create Prima::IniFile; my $ini = create Prima::IniFile FILENAME; my $ini = create Prima::IniFile FILENAME, default => HASHREF_OR_ARRAYREF; my $ini = create Prima::IniFile file => FILENAME, default => HASHREF_OR_ARRAYREF; my @sections = $ini->sections; my @items = $ini->items(SECTION); my @items = $ini->items(SECTION, 1); my @items = $ini->items(SECTION, all => 1); my $value = $ini-> get_values(SECTION, ITEM); my @vals = $ini-> get_values(SECTION, ITEM); my $nvals = $ini-> nvalues(SECTION, ITEM); $ini-> set_values(SECTION, ITEM, LIST); $ini-> add_values(SECTION, ITEM, LIST); $ini-> replace_values(SECTION, ITEM, LIST); $ini-> write; $ini-> clean; $ini-> read( FILENAME); $ini-> read( FILENAME, default => HASHREF_OR_ARRAYREF); my $sec = $ini->section(SECTION); $sec->{ITEM} = VALUE; my $val = $sec->{ITEM}; delete $sec->{ITEM}; my %everything = %$sec; %$sec = (); for ( keys %$sec) { ... } while ( my ($k,$v) = each %$sec) { ... } METHODS
add_values SECTION, ITEM, @LIST Adds LIST of string values to the ITEM in SECTION. clean Cleans all internal data in the object, including the name of the file. create PROFILE Creates an instance of the class. The PROFILE is treated partly as an array, partly as a hash. If PROFILE consists of a single item, the item is treated as a filename. Otherwise, PROFILE is treated as a hash, where the following keys are allowed: file FILENAME Selects name of file. default %VALUES Selects the initial values for the file, where VALUES is a two-level hash of sections and items. It is passed to read, where it is merged with the file data. get_values SECTION, ITEM Returns array of values for ITEM in SECTION. If called in scalar context, and there is more than one value, the first value in list is returned. items SECTION [ HINTS ] Returns items in SECTION. HINTS parameters is used to tell if a multiple-valued item must be returned as several items of the same name; HINTS can be supplied in the following forms: items( $section, 1 ) items( $section, all => 1); new PROFILE Same as create. nvalues SECTION, ITEM Returns number of values in ITEM in SECTION. read FILENAME, %PROFILE Flushes the old content and opens new file. FILENAME is a text string, PROFILE is a two-level hash of default values for the new file. PROFILE is merged with the data from file, and the latter keep the precedence. Does not return any success values but, warns if any error is occurred. replace_values SECTION, ITEM, @VALUES Removes all values form ITEM in SECTION and assigns it to the new list of VALUES. section SECTION Returns a tied hash for SECTION. All its read and write operations are reflected in the caller object, which allows the following syntax: my $section = $inifile-> section( 'Sample section'); $section-> {Item1} = 'Value1'; which is identical to $inifile-> set_items( 'Sample section', 'Item1', 'Value1'); sections Returns array of section names. set_values SECTION, ITEM, @VALUES Assigns VALUES to ITEM in SECTION. If number of new values are equal or greater than the number of the old, the method is same as replace_values. Otherwise, the values with indices higher than the number of new values are not touched. write Rewrites the file with the object content. The object keeps an internal modification flag under name "{changed}"; in case it is "undef", no actual write is performed. AUTHORS
Anton Berezin, <tobez@plab.ku.dk> Dmitry Karasik <dmitry@karasik.eu.org> perl v5.14.2 2009-02-24 Prima::IniFile(3)
All times are GMT -4. The time now is 07:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy