[英]/usr/bin/cut: Argument list too long in bash script
I loaded a csv file into a variable and then I am trying to cut out some columns which results in this error /usr/bin/cut: Argument list too long . 我将一个csv文件加载到一个变量中,然后尝试剪切出一些列,从而导致此错误/ usr / bin / cut:参数列表过长 。 Here is what I did: 这是我所做的:
if [ $# -ne 1 ]; then
echo "you need to add the file name as argument"
fi
echo "input file name $1"
input_file=$(<$1)
#cut the required columns.
cut_input_file=$(cut -f 1,2,3,5,8,9,10 -d \| $input_file)
echo $(head $cut_input_file)
What am I missing? 我想念什么?
Reason of that error is your use of $input_file
which has full file data. 该错误的原因是您使用了具有完整文件数据的$input_file
。
You need to run cut
on the file not on the file content so use: 您需要对文件而不是文件内容进行cut
,因此请使用:
cut -f 1,2,3,5,8,9,10 -d '|' "$1"
To run cut
against file content use: 要针对文件内容运行cut
,请使用:
cut -f 1,2,3,5,8,9,10 -d '|' <<< "$input_file"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.