[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. gawk "!($2 in a){a[$2];$3=\"\";print}" yuanshi.txt >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{print a[$2],$1}" jingjian.txt quhao.txt >result.txt
复制代码

TOP

C:\Test>gawk "!($2 in a){a[$2];$3=\"\";print}" yuanshi.txt >jingjian.txt

C:\Test>gawk "NR==FNR{a[$2]=$1}NR>FNR{print a[$2],$1}" jingjian.txt quhao.txt >result.txt

C:\Test>type result.txt
1354910 753
1354920 769
1354950 735
1354960 736
1354964 731

C:\Test>gawk --version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.

TOP

你的gawk版本是多少?
在gawk上面加一句chcp 936行吗?
在gawk上面加一句chcp 437行吗?

TOP

  1. gawk -F"\t" "!($2 in a){a[$2];$3=\"\";print}" yuanshi.txt >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{print a[$2],$1}" jingjian.txt quhao.txt >result.txt
复制代码

TOP

  1. gawk -F"[ \t]" "!($2 in a){a[$2];$3=\"\";print}" yuanshi.txt >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{print a[$2],$1}" jingjian.txt quhao.txt >result.txt
复制代码

TOP

  1. gawk -F" \t" "($1!=p+1)||(!($2 in a)){a[$2];print $1,$2}{p=$1}" data.txt >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{print a[$2],$1}" jingjian.txt quhao.txt >result.txt
复制代码

TOP

你是不是把\t前面的空格丢掉了?

TOP

  1. type data.txt | gawk -F"[ \t]" "($1!=p+1)||(!($2 in a)){a[$2];print $1,$2}{p=$1}" >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR&&($2 in a){print a[$2],$1}" jingjian.txt quhao.txt >result.txt
复制代码

TOP

  1. type data.txt | gawk -F"[ \t]" "($1!=p+1)||(!($2 in a)){a[$2];print $1,$2}{p=$1}" >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR&&($2 in a){print $1,a[$2]}" quhao.txt jingjian.txt >result.txt
复制代码
不知道你为什么认为大于500KB才正常,我这个代码得到的结果大于9KB,你能否帮忙指出哪行数据丢掉了?

TOP

  1. type data.txt | gawk -F"[ \t]" "($1!=p1+1)||(p2!=$2){a[$2];print $1,$2}{p1=$1;p2=$2}" >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR&&($2 in a){print $1,a[$2]}" quhao.txt jingjian.txt >result.txt
复制代码
这样可以得到大于500KB的文件,你把这个结果跟37楼大于600KB的比较一下,看看到底需要哪个。

TOP

如果要求jingjian.txt和result.txt行数一样的话(50046行),可以这样做:
  1. type data.txt | gawk -F"[ \t]" "($1!=p1+1)||(p2!=$2){a[$2];print $1,$2}{p1=$1;p2=$2}" >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{if($2 in a)print $1,a[$2];else print $1}" quhao.txt jingjian.txt >result.txt
复制代码

TOP

37楼得到的结果是50023行,41楼得到的结果是50046行,到底哪个是正确的?

TOP

41楼比37楼多出如下行:
1349320 10
1349380 10
1349740 10
1349970 10
1380050
1380062 592
1534346 354
1534666
1534967 951
1535255 999
1536280 769
1536380 757
1536545 516
1555950 595
1572220 22
1860100 10
1861800 10
1863900 371
1879637 516
1880944 931
1881100 10
1887888 771
1893893 755

根据楼主的规则,这些行是需要保留下来的吗?

TOP

回复 45楼 的帖子

这跟你顶楼的描述不是冲突了吗?你的要求到底是怎样的呢?
应该将归属地相同连续号段进行精简
如1331000 至1331019都是上海,保留1331000即可
而往下1351210至1351219还是上海,同理保留1351210

TOP

  1. type data.txt | gawk -F"[ \t]" "(NR!=1)&&($1!=p1+1){print p1+1\" 未知\"}($1!=p1+1)||(p2!=$2){print $1,$2}{p1=$1;p2=$2}" >jingjian.txt
  2. gawk "NR==FNR{a[$2]=$1}NR>FNR{if($2 in a)print $1,a[$2];else print $1}" quhao.txt jingjian.txt >result.txt
复制代码
57楼得到的结果是50641行
我的代码得到和54楼得到的结果一样都是50679行

TOP

返回列表