I assume the <br>
in your question at the end of the date
column is something unwanted for. In any case, it can be removed easily if it is present. However, coming to the main part you can achieve what you are trying to do using,
sort -k 2n filename.txt
Now, the above command would give the output in a sorted manner. Now, the below command should give what you look for.
sort -k 2n filename.txt | awk '/2013\/12\/03/ {exit} {print}'
Explanation
The sort command basically sorts the file based on the second column which is the date. So I modified your input file to test the command if it works since the input file has all the data sorted by default. After that, the awk
command prints all the lines till we encounter a particular match.
Testing
cat filename.txt
647919 2014/01/01
647946 2012/11/30
647955 2011/01/04
648266 2013/12/03
648267 2013/12/03
648674 2013/12/04
Now, sort -k 2n filename.txt
output is,
647955 2011/01/04
647946 2012/11/30
648266 2013/12/03
648267 2013/12/03
648674 2013/12/04
647919 2014/01/01
Now we are satisfied that the file is sorted on the second column. Now, to select values UPTO a particular date,
sort -k 2n filename.txt | awk '/2013\/12\/03/ {exit} {print}'
In the above example, I get all the values upto 2013/12/03
. The output is,
647955 2011/01/04
647946 2012/11/30
No, the <br>
is part of my file
If this is the case, we can tweak the command slightly as below.
awk '{print $1, substr($2, 1, length($2)-4)}' filename.txt |
sort -k 2n filename.txt | awk '/2013\/12\/03/ {exit} {print}'
So I am just removing all the <br>
tags from the second column and then piping the above mentioned command.
References
https://unix.stackexchange.com/a/11323/47538
https://unix.stackexchange.com/a/83069/47538