1

I have two files:

Ref.txt which contains:

ABCDEFG,15147,1,2,6
HIJKLMN,500,3,4

and Seq.txt which contains:

ABCXXXX
ABCDEXX
IIJKXXX
HIHKXXX
LMNOPQR
BBCDEXX
STUVWXY

I would like to replace the certain lines in the Seq.txt file. The indices of the lines that should be replaces are listed in fields 3-end of Ref.txt file, and what the lines should be replaced with is located in field 1 of the same line in the Ref.txt file. The output I am looking for in this example is this:

ABCDEFG
ABCDEFG
HIJKLMN
HIJKLMN
LMNOPQR
ABCDEFG
STUVWXY
3
awk -F, '
  NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next} 
  FNR in a {$0 = a[FNR]} 
  1
' Ref.txt Seq.txt 
ABCDEFG
ABCDEFG
HIJKLMN
HIJKLMN
LMNOPQR
ABCDEFG
STUVWXY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.