Awk 按位置相交两个文本文件

Awk 按位置相交两个文本文件,awk,Awk,我有两个文本文件,我需要按位置相交 文件1 文件2 预期产量 cat02 2 xxx sss www cat02 3 swe ede rrr cat02 4 aqw ede efd cat02 5 aws ede as 我尝试通过对两个文件进行排序来使用join,但无法获取位置能否请您尝试使用GNUawk中显示的示例编写并测试以下内容 awk ' FNR==NR{ start[$1]=$2 till[$1]=$3 next } $2>=start[$1] &&

我有两个文本文件,我需要按位置相交

文件1

文件2

预期产量

cat02 2 xxx sss www
cat02 3 swe ede rrr
cat02 4 aqw ede efd
cat02 5 aws ede as

我尝试通过对两个文件进行排序来使用join,但无法获取位置

能否请您尝试使用GNU
awk
中显示的示例编写并测试以下内容

awk '
FNR==NR{
  start[$1]=$2
  till[$1]=$3
  next
}
$2>=start[$1] && $2<=till[$1]
' Input_file1  Input_file2
awk'
FNR==NR{
开始[$1]=$2
直至[$1]=$3
下一个
}

$2>=start[$1]&&&$2=start[$1]&&&$2欢迎使用堆栈溢出。这也是一个面向专业和热情程序员的问答页面。请在问题中添加您自己的代码。你至少要展示你自己为解决这个问题所做的大量研究。文件1是否总是只包含一行,并且是否打算使大写和小写不同(Cat02与Cat02)?@Cyrus抱歉,只是键入错误我已经做了更改,是的,两者都是小写的如果我在文件1中有多个位置(每行一个),我如何更改此代码以查找所有位置@RavinderSingh13@user90,IMHO我想请你为这一个打开一个新的问题,因为未来的用户引用此线程将感到困惑,否则请打开一个新的问题,同样感谢你。
cat02 2 xxx sss www
cat02 3 swe ede rrr
cat02 4 aqw ede efd
cat02 5 aws ede as
awk '
FNR==NR{
  start[$1]=$2
  till[$1]=$3
  next
}
$2>=start[$1] && $2<=till[$1]
' Input_file1  Input_file2
awk '                             ##Starting awk program from here.
FNR==NR{                          ##Checking condition if FNR==NR which will be TRUE when Input_file1 is being read.
  start[$1]=$2                    ##Creating start with index $1 and value is $2.
  till[$1]=$3                     ##Creating til with index $1 and value is $3 here.
  next                            ##next will skip all further statements from here.
}
$2>=start[$1] && $2<=till[$1]     ##Checking condition if start with 1st field index value is greater than 2nd field and lesser than till value then print line.
' Input_file1  Input_file2        ##Mentioning Input_file names here.