I want to sort contents of file.txt
by date. The date to sort is in the fourth table data <td></td>
tag
E.g. Content of file.txt
:
<tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2018Mar01</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2017Jan31</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2018Apr02</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2017Dec25</td></tr>
Desired output: How can I do this?
<tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2017Jan31</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2017Dec25</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2018Mar01</td></tr> <tr><td>some_name_here</td><td>number_code_here</td><td>2018Mar31</td><td>2018Apr02</td></tr>
I've been using sort
command but it's not working.
cat file.txt 2> /dev/null | sort -t'>' -k9n -k9.4M -k9.7n
EDIT: I found this reference link but still doesn't work correctly. https://stackoverflow.com/a/16060031/7842707
file.txt
is just a text file. It's not the final HTML file. After sorting that out, I'll be redirecting the output to an HTML file. As you can see, there's no HTML tag or table tag in it.