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

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

file1 contains multiple alphabetic sequences:

AETYUIOOILAKSJ
EAYEURIOPOSIDK
RYXURIAJSKDMAO
URITORIEJAHSJD
YWQIAKSJDHFKCM
HAJSUDIDSJSIAJ
AJDHDPFDIXSIBJ
JAQIAUXCNC         


        
5条回答
  •  执笔经年
    2021-01-29 05:16

    With awk + grep pipeline:

    awk '{ pat=sprintf("%*s", int($0)-1, ""); gsub(" ", ".", pat); 
           printf "^%s%s\n", pat, substr($0, length) }' file2 | grep -f- file1
    

    The output:

    AETYUIOOILAKSJ
    RYXURIAJSKDMAO
    URITORIEJAHSJD
    JAQIAUXCNCVUFO
    

提交回复
热议问题