2233|charles harris |g.m. |sales |12/12/52|90000
9876|bill johnson |director |production|03/12/50|130000
5678|robert dylan |d.g.m. |marketing |04/19/43|85000
2365|john woodcock |director |personnel |05/11/47|120000
5423|barry wood |chairman |admin |08/30/56|160000
1006|gordon lightfoot|director |sales |09/03/38|140000
6213|michael lennon |g.m. |accounts |06/05/62|105000
1265|p.j. woodhouse |manager |sales |09/12/63|90000
4290|neil o'bryan |executive|production|09/07/50|65000
2476|jackie wodehouse|manager |sales |05/01/59|110000
6521|derryk o'brien |director |marketing |09/26/45|125000
3212|bill wilcocks |d.g.m. |accounts |12/12/55|85000
3564|ronie trueman |executive|personnel |07/06/47|75000
2345|james wilcox |g.m. |marketing |03/12/45|110000
0110|julie truman |g.m. |marketing |12/31/40|95000
原谅我的可怜的格式,这是该文本文件包含我的问题是如何排序的所有关键区域5即是日期,例如| 40年12月31日| MM / DD / YY和日期从最旧到命令行最年轻的休息吗?分隔符是这个|
这是一个选项:
cat file.txt \
| awk 'BEGIN {FS="|"}{ split($5,date,/\//); $5 = date[3] "/" date[2] "/" date[1]; print $1 "|" $2 "|" $3 "|" $4 "|" $5 "|" $6 }' \
| sort -k5,5 -t"|" \
| awk 'BEGIN {FS="|"}{ split($5,date,/\//); $5 = date[3] "/" date[2] "/" date[1]; print $1 "|" $2 "|" $3 "|" $4 "|" $5 "|" $6}'
说明: