从最早的输出员工老三这个文本文件中的命令行?

问题描述 投票:0回答:1
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和日期从最旧到命令行最年轻的休息吗?分隔符是这个|

command-line
1个回答
0
投票

这是一个选项:

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}'

说明:

  1. 猫:猫文件
  2. AWK:修复日期格式为YY / MM / DD
  3. 排序:按固定日期列
  4. AWK:还原栏的日期格式
© www.soinside.com 2019 - 2024. All rights reserved.