Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the simplest in awk... 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

what I have now:
Code:
$ cat f1
abc:3424
addf:4523
fsfs:2354
$ cat f2
abc:3535
fsfs:2354
$ awk -F\: '{print $1}' f1 f2|sort -u|while read a;do echo "$a :: `awk -F\: -vb=$a '$1 == b {print $2}' f1` : `awk -F\: -vc=$a '$1 == c {print $2}' f2`";done
[red]abc :: 3424 : 3535
addf :: 4523 :
fsfs :: 2354 : 2354[/red]
$

and what I would like to have on output:
Code:
[red]abc :: 3424 : 3535
addf :: 4523 : -
fsfs :: identical : identical[/red]
 
Something like this ?
Code:
 awk -F':' '
NR==FNR{a[$1]=$2;next}
{if($1 in a)if(a[$1]==$2)x=y="identical";else {x=$2;y=a[$1]}else{x=$2;y="-"}
 printf "%s :: %s : %s\n",$1,x,y}
' f2 f1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Even simpler:
awk -F':' 'NR==FNR{a[$1]=$2;next}{x=$2;if($1 in a)if(a[$1]==$2)x=y="identical";else y=a[$1];else y="-";printf "%s :: %s : %s\n",$1,x,y}' f2 f1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top