2 lists, show differences plus or minus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 lists, show differences plus or minus
# 1  
Old 03-17-2015
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

Code:
    device1 5
    decive2 10
    decive3 10
    device4 10
    device5 10
    device6 20

list2

Code:
    device1 10
    decive2 10
    decive3 10
    device4 10
    device5 10
    device6 10

report

Code:
    device1 5
    device6 -10


Last edited by Scrutinizer; 03-17-2015 at 04:41 PM.. Reason: CODE tags
# 2  
Old 03-17-2015
Please use code tags as required by forum rules!

Try
Code:
awk 'FNR==NR {CNT[$1]=$2; next} $2!=CNT[$1] {print $1, $2-CNT[$1]}' file[12]
device1 5
device6 -10

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Sed/awk to tell differences between two lists

Greetings all, I have two output lists from a log that I am working with. Below are the examples. except, the lists are in the thousands. list1.out FEA1234 FEA4343 FEA3453 FEA3413 FEA34A3 FEA3433 .... list2.out FEA1235 (3 Replies)
Discussion started by: jeffs42885
3 Replies

3. UNIX for Dummies Questions & Answers

Minus 5 minutes

Hi, I need to subtract 5 minutes from the date. Example $date +"%Y-%m-%d-%H.%M.%S" displays 2014-06-26-06.06.38 I want to show it as 2014-06-26-06.01.38 (5 mins are subtracted from date) Any help would be appreciated. I am currently on AIX version 6.1 -Vrushank (10 Replies)
Discussion started by: vrupatel
10 Replies

4. Shell Programming and Scripting

Minus minus to plus

Hi there, I have a problem with arithmetic ops in awk. Here is what my script does right now. while read nr val ; do case $nr in 400) awk '$2~/eigenvectors/ {print $NF-'$val'};' input.txt >> output.txt;; esac done < frames.txtI have a file named frames.txt with two columns (nr and... (2 Replies)
Discussion started by: tobias1234
2 Replies

5. Shell Programming and Scripting

How to make diff show differences one line at a time and not group them?

Is there a way to tell diff to show differences one line at a time and not to group them? For example, I have two files: file1: line 1 line 2 line 3 diff line 4 diff line 5 diff line 6 line 7 file2: line 1 line 2 line 3 diff. line 4 diff. line 5 diff. line 6 line 7 (13 Replies)
Discussion started by: mmr11408
13 Replies

6. Solaris

How to show time minus 60 minutes?

In Redhat it is easy.... date --date="60 minutes ago" How do you do this in Solaris? I got creative and got the epoch time but had problems.. EPOCHTIME=`truss date 2>&1 | grep "time()" | awk '{print $3 - 900}'` echo $EPOCHTIME TIME=`perl -e 'print scalar(localtime("$EPOCHTIME")),... (5 Replies)
Discussion started by: s ladd
5 Replies

7. Shell Programming and Scripting

Minus of files

File 1 contains data : CALL_ID SOR_ID SEG_SEQ_NUM CHK_PNT_MENU_TYPE_CD PTNR_ID ACTVN_RTRN_CD PRIM_ACTVN_DCLN_REAS_CD SCNDRY_ACTVN_DCLN_REAS_CD ACTVN_SCCS_IND CARD_ACTVTD_IND MAX_ACTVN_FAILD_ATMP_IND EDW_PUBLN_ID File 2 contains data: PRIM_ACTVN_DCLN_REAS_CD... (3 Replies)
Discussion started by: ysvsr1
3 Replies

8. 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

9. 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

10. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies
Login or Register to Ask a Question