需求:一文件内容如下,求第一列的最大值和最小值
1 1220
2 1221
3 1222
3 1223
4 1224
5 1225
12 1226
12 1227
12 1228
12 1229
12 1230
命令如下
求最小值:
sed '/^$/d' test.txt|awk 'NR==1{min=$1;next}{min=min<$1?min:$1}END{print min}'
求最大值:
sed '/^$/d' test.txt|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'
利用sed删除空行,利用awk筛选出最大值和最小值。