match index notation of file1 to the index of file2 and pull out matching rows

后端 未结 5 595
夕颜
夕颜 2021-01-29 04:47

file1 contains multiple alphabetic sequences:

AETYUIOOILAKSJ
EAYEURIOPOSIDK
RYXURIAJSKDMAO
URITORIEJAHSJD
YWQIAKSJDHFKCM
HAJSUDIDSJSIAJ
AJDHDPFDIXSIBJ
JAQIAUXCNC         


        
5条回答
  •  悲&欢浪女
    2021-01-29 04:57

    $ cat tst.awk
    NR==FNR {
        lgth = length($0)
        pos2char[substr($0,1,lgth-1)] = substr($0,lgth,1)
        next
    }
    {
        for (pos in pos2char) {
            if ( substr($0,pos,1) == pos2char[pos] ) {
                print
                next
            }
        }
    }
    
    $ awk -f tst.awk file2 file1
    AETYUIOOILAKSJ
    RYXURIAJSKDMAO
    URITORIEJAHSJD
    JAQIAUXCNCVUFO
    

提交回复
热议问题