[英]sort write failed standard output broken pipe--Linux
I am using following commands in my script: 我在脚本中使用以下命令:
max_length=`awk '{print length}' $File_Path_Name/$filnm | sort -nr | head -1`;
min_length=`awk '{print length}' $File_Path_Name/$filnm | sort -nr | tail -1`;
where the filenm
variable contains the name of the file and File_Path_Name
contains the directory path. 其中
filenm
变量包含文件名, File_Path_Name
包含目录路径。
While executing this from script I am getting the error 从脚本执行此操作时出现错误
sort: write failed: standard output: Broken pipe
排序:写入失败:标准输出:管道损坏
Any suggestions what I am doing wrong? 有什么建议我做错了吗?
you don't need to scan the file twice for getting max/min try 您无需两次扫描文件即可获得最大/最小尝试次数
$ read max min < <(awk '{print length}' file | sort -nr | sed -n '1p;$p' | paste -s)
or you can avoid sorting as well by calculating max/min within awk
或者您也可以通过计算
awk
内的最大值/最小值来避免排序
$ awk '{len=length}
NR==1 {max=min=len}
max<len{max=len}
min>len{min=len}
END {print max, min}' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.