根据shell脚本中的所有范围检查编号

时间:2015-05-11 06:19:14

标签: shell unix awk

我必须检查file1中针对file2的所有范围的具体数字。

cat file1

20 00000000000328051779 00000000000000000000922820669 xx 20 00000000000228051777 00000000000000000000922820669 xx 20 00000000000228051813 00000000000000000000922820669 xx

cat file2

 228051777, 228051779
 228051811, 228051814
 228051817, 228051817

输出

20 00000000000228051777 00000000000000000000922820669 xx 20 00000000000228051813 00000000000000000000922820669 xx

到目前为止,这是我的代码。得到了正确的输出但是读取数千条记录的速度太慢了。

   #segregate records
awk -F', +' '
  # 1st pass (fileB): read the lower and upper range bounds
 FNR==NR { lbs[++count] = $1+0; ubs[count] = $2+0; next }
  # 2nd pass (FILES): check each line against all ranges.
 { 
   for(i=1;i<=count;++i) {
   anum=substr($1,3,22); sub(/^0+/, "", anum)
    if (anum+0 >= lbs[i] && anum+0 <= ubs[i]) { print; next }
   }
 }
' file2 file1

1 个答案:

答案 0 :(得分:0)

您可以使用此#include <vector> class A{ public: A(int a) : a(a){ } int getInt() const{ return a; } A(const A&) = delete; /* to deny copy-construction */ private: int a; }; int main(int argc, char* argv[]){ std::vector<A> vec; vec.emplace_back(3); /* tries to call copy constructor */ vec.push_back(A(3)); /* tries to call copy constructor */ vec.push_back(std::move(A(3))); /* tries to call copy constructor */ return 0; }

awk