Off by one error... indexes start at 0 then 1 then 2 etc... so you need to use 2 instead of 3 for the 3rd key. In this statement x.split("|")[3] you are asking for the 4th item in the split and there are only 3 items in your split, hence the keyError message.
I recommend using
keys = [ x.split("|")[2].rstrip("\n") for x in open("dm.txt").readlines()]
Additionally:
Try using full paths in read() and open() functions
i.e:
from configparser import ConfigParser
config = ConfigParser()
config.read("C:\\PathToIni\\demo.ini")
# cutting the values of file from column 3
keys = [ x.split("|")[2].rstrip("\n") for x in open("C:\\PathToTxt\\dm.txt").readlines()]
vals = [config["DEMFILE"][x] for x in keys]
print(vals)
This outputs:
["'XYZABC'", "'Kolkata'", "'123'"]
for me using the two files:
dm.txt:
A|B|Name
VB|C|City
SDF|JK|Code
demo.ini
[DEMFILE]
Name='XYZABC'
Surname='TYUIO'
Code='123'
City='Kolkata'
This answer also shows how to create a generic agnostic relative path
Relative paths in Python