Sure you can, but that's not what your code does. If you want to sort column 16, you will first have to select the 16th column entirely
, before you can sort it. So you would do:
- Open your input file.
- Read it, line by line. Extract column 16, push it to an array.
- Close your input file.
- Sort your array.
- Open your output file.
- Write your sorted array.
- Close your output file.
What you certainly can't do is reading the input one line at a time, writing something for each line, and then expect the entire thing to be sorted when you're done.