awkでデータ項目を背番号に置換(ID番号に置換)する。
想定されるデータ
networkB.txt
234 334
234 532
12 234
9082 334
5 6
を
次のルールでID付けをし、
[名前 ID]
testnodehenkan.txt
5 0
6 1
12 2
234 3
334 4
532 5
9082 6
下のような形に置換する。
出力
3 4
3 5
2 3
6 4
0 1
名前が文字列で、それに数字のID
をつけるときにも応用できるはず..。
awk '{print $1"\n"$2}' networkB.txt | sort -n | uniq > testnodeB.txt awk '{print NR-1,$1}' testnodeB.txt > testnodehenkan.txt awk 'BEGIN{while((getline a < "testnodehenkan.txt") > 0){split(a,b," ");c[b[ 2]]=b[1];} }{print c[$1]" "c[$2]}' networkB.txt