linux - 运行带有长参数的 linux 命令时出现文件名太长错误

标签 linux paste cut

我正在尝试从 100 个文件中剪切单个列,并使用此 linux 命令将它们粘贴在一起:

paste <(cut -f 5 file_1.tsv) <(cut -f 5 file_2.tsv) <(cut -f 5 file_3.tsv) ... <(cut -f 5 file_100.tsv) > combined.tsv

我收到这个错误:

File name too long

有什么解决办法的建议吗?

最佳答案

您收到此消息的原因可能是命令行大小有限。我建议你尝试用循环来做。这是您可以执行的操作的示例 --- 请注意,因为顺序可能不是您想要的:

#!/bin/bash
echo "" >  combined.tsv

#build your file list
find . -name "file*tsv" |sort -k1 > list_files.lst

#the process the list
while read x ; do
  x=`basename ${x}`
  paste <(cat combined.tsv) <(cut -f 5 ${x} ) > combined${x}.tsv
  mv combined${x}.tsv combined.tsv
done< list_files.lst

#you do not need it anymore
rm list_files.lst

(这个要放到一个文件里,比如myscript.sh,然后chmod +x myscript.sh,然后像下面这样运行

./myscript.sh

)

关于linux - 运行带有长参数的 linux 命令时出现文件名太长错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36659603/

相关文章:

linux - 将 ffmpeg -sseof 与管道一起使用

stub 上的 Java RMI ClassNotFoundException 发生在 Linux 而不是 Windows

string - 连接字符串中的数值

javascript在textarea中捕获粘贴事件

bash - 如何在 bash 中使用 cut 命令显示除指定列之外的所有列?

linux - 将 Postgresql 更新到较新版本会破坏旧代码

linux - 无法访问在 ec2-instance 上运行的 Jenkins

excel - VBA - 从多个 Excel 文件复制和粘贴到单个 Excel 文件

linux - 使用 df 获取可用磁盘空间以仅以 kb 为单位显示可用空间?

unix - 如何从 unix 中的 cut 命令的结果中提取子字符串?