/ usr / bin / cut:bash脚本中的参数列表太长了

时间:2015-07-07 13:01:47

标签: linux bash

我将csv文件加载到变量中然后我试图删除一些导致此错误的列 / usr / bin / cut:参数列表太长。这是我做的:

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)

我错过了什么?

1 个答案:

答案 0 :(得分:3)

该错误的原因是您使用具有完整文件数据的$input_file

您需要在不在文件内容上的文件上运行cut,因此请使用:

cut -f 1,2,3,5,8,9,10 -d '|' "$1"

要针对文件内容运行cut

cut -f 1,2,3,5,8,9,10 -d '|' <<< "$input_file"
相关问题