Reputation
Top tag
Next privilege 75 Rep.
Set bounties
Badges
1 7
Impact
~6k people reached

  • 0 posts edited
  • 0 helpful flags
  • 10 votes cast
Nov
8
accepted Compare 2 Columns in 2 different files
Nov
8
comment Compare 2 Columns in 2 different files
Let us continue this discussion in chat.
Nov
7
comment Compare 2 Columns in 2 different files
unfortunately the last command is not working. nawk: syntax error at source line 1 context is BEGIN { print "TABLE,REF-IO,HEAD-IO,DIFF-IO,REF-SELECT,HEAD-SELECT,DIFF-SELECT"; OFS = ", "; FNR==NR >>> { <<< nawk: illegal statement at source line 1 missing }
Nov
7
comment Compare 2 Columns in 2 different files
Is there a way to include the header print in the command?
Nov
7
comment Compare 2 Columns in 2 different files
having wrong output. nawk 'FNR==NR {A[$1]=$2;B[$1]=$3; next}{if ( $1 not in A ) {A[$1] = B[$1] = 0}; diff_io = $2 - A[$1];diff_sel= $3 - B[$1];C[$1] = 1}; diff_io || diff_sel {print line; line = $1 " " $2 " " A[$1] " " diff_io " " $3 " " B[$1] " " diff_sel}END {for (name in A) {if ( name not in C ) {print name, 0, A[name], -A[name], 0, B[name], -B[name]}} print line}' head_file ref_file testing 20 0 20 10 0 10 jobs 15 0 15 20 0 20 issues 0 0 1 1 work 15 0 15 25 0 25 Total 0 0 -0 0 0 -0 issues 0 -0 0 -0 jobs 0 0 -0 0 0 -0 testing 0 0 -0 0 0 -0 work 0 0 -0 0 0 -0 Total 50 0 50 26 0 26
Nov
7
comment Compare 2 Columns in 2 different files
column No. 1 values that exist in one of the files should always be displayed as shown in my example
Nov
7
comment Compare 2 Columns in 2 different files
@Costas, column No. 1 values that exist in one of the files should always be displayed as shown in my example
Nov
7
comment Compare 2 Columns in 2 different files
@Costas, No the files may have some different column No. 1 values and of course have different number of rows.
Nov
7
comment Compare 2 Columns in 2 different files
@John1024 I need to substract column 2 of ref_file by column 2 of head_file and show their diffrence, in addition substract column 3 of ref_file by column 3 of head_file and show their difference. All the above based on column 1 of both file and the output should not contain the rows with diff_column_2(DIFF-IO) = diff_column_3(DIFF-SELECT) = 0. Noting that the order can be random except the last row which exists in both files and should remain at the END in the output.
Nov
7
asked Compare 2 Columns in 2 different files
Sep
27
comment Compare first column of 2 files based on the second column using the delimiter ;
I found the solution. nawk -F";" 'BEGIN{OFS=","; print "FUNCTION,HEAD,REF,DIFF"} FNR==NR{a[$2]=$1;next} {if ($1 != 0) {print $2,$1,a[$2]*1,a[$2]-$1} ; delete a[$2]} END{for (i in a){if (a[i] != 0) print i,0,a[i],a[i]}}' ref_file head_file
Sep
27
revised Compare first column of 2 files based on the second column using the delimiter ;
deleted 2 characters in body
Sep
26
comment Compare first column of 2 files based on the second column using the delimiter ;
It worked properly but using nawk and not awk. Is there a way not to display functions having REF=HEAD=0 ? @chaos
Sep
26
revised Compare first column of 2 files based on the second column using the delimiter ;
Improve title
Sep
26
accepted Compare first column of 2 files based on the second column using the delimiter ;
Sep
26
revised Compare first column of 2 files based on the second column using the delimiter ;
edited body
Sep
25
asked Compare first column of 2 files based on the second column using the delimiter ;
Aug
16
awarded  Notable Question
May
8
comment Using Unix, when detecting a pattern, we need to detect its corresponding other pattern
I'm not able to pass to the command a variable $pattern. Can you please assist? gawk "/===/ {SEC=$0;PRINTED=0} /$pattern/ {if(!PRINTED) print SEC; print $0; PRINTED=1;}" describe.txt
May
8
comment Using Unix, when detecting a pattern, we need to detect its corresponding other pattern
Thank you Eric! gawk worked properly!