I have a text file below:

```
asd|2016-03-17 14:33:05|asd|
asd|2017-03-17 14:27:25|asd|
asd|2016-03-15 14:27:25|asd|
asd|2016-03-17 14:33:05|asd|
asd|2016-03-16 14:33:05|asd|

```

I tried the code below but I am getting "IndexError: string index out of range" error. 

```
with open(file) as inf:
    for line in inf:
        data = line.split('|')
        sorted_data = sorted(data, key=lambda line: line[1])

```

Desired Output: I want to sort the text file using the second column delimited by '|' and output it to another file.