我有一个带有多个管道的 bash/zsh 命令|,在使用set -o pipefail. 为简单起见,假设命令是
set -o pipefail; echo "123456" | head -c2 | grep 5 | cat
Run Code Online (Sandbox Code Playgroud)
如何快速找出哪个命令首先失败以及原因?我知道我可以检查退出代码,但这并不能显示管道的哪一部分首先失败。
有没有比逐个构建管道并检查第一个失败退出代码的相当冗长的检查更简单的方法?
编辑:我删除了我编写的人为代码示例,因为它使人们对我询问的目的感到困惑。提示这个问题的实际命令是:
set -o pipefail; echo "123456" | head -c2 | grep 5 | cat
Run Code Online (Sandbox Code Playgroud) 我有一个包含数百万行的巨大xz压缩文本文件huge.txt.xz,该文件太大而无法保持未压缩(60GB)。
我想从那个巨大的文本文件中快速过滤/选择大量行(~1000s)到一个文件中filtered.txt。例如,可以在单独的文本文件中指定要选择的行号,select.txt格式如下:
10
14
...
1499
15858
Run Code Online (Sandbox Code Playgroud)
总的来说,我设想了一个如下的 shell 命令,其中“待确定”是我正在寻找的命令:
10
14
...
1499
15858
Run Code Online (Sandbox Code Playgroud)
我设法awk从一个密切相关的问题中找到了一个几乎可以完成工作的程序 - 唯一的问题是它需要一个文件名而不是从stdin读取。不幸的是,我不太了解awk脚本,也不知道awk以这种方式更改它以在这种情况下工作。
这就是现在有效的方法,缺点是有 60GB 的文件存在而不是流式传输:
xz -dcq huge.txt.xz | "TO BE DETERMINED" select.txt >filtered.txt
Run Code Online (Sandbox Code Playgroud)
灵感:https : //unix.stackexchange.com/questions/612680/remove-lines-with-specific-line-number-specified-in-a-file
第一次使用命令行,我尝试在带有 M1 芯片的 Mac 环境中安装 Bioconda 软件包(fastp 和 Bowtie1),但我不断收到相同的错误:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- fastp
Current channels:
- https://conda.anaconda.org/bioconda/osx-arm64
- https://conda.anaconda.org/bioconda/noarch
- https://conda.anaconda.org/conda-forge/osx-arm64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/osx-arm64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-arm64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the …Run Code Online (Sandbox Code Playgroud) 我需要处理输入文件值,将它们转换为逗号分隔的字符串(而不是空格),以便将它们传递给 CLI 程序。为此,我想通过 Python 函数运行输入文件。如何在同一规则的 params 部分引用该规则的输入文件?
这是我尝试过的,但它不起作用:
rule a:
input:
foo="a.txt",
bar=expand({build}.txt,build=config["build"]),
output:
baz=result.txt,
params:
joined_bar=lambda w: ",".join(input.bar), # this doesn't work
shell:
"""
qux --comma-separated-files {params.joined_bar} \
--foo {input.foo} \
>{output.baz}
"""
Run Code Online (Sandbox Code Playgroud)
它失败了:
InputFunctionException:
AttributeError: 'builtin_function_or_method' object has no attribute 'bar'
Run Code Online (Sandbox Code Playgroud)
潜在相关但(过于)复杂的问题:
如何使用扩展输入定义 Snakemake 规则的参数
Is Snakemake params 函数在输入文件存在之前评估?
autoreconf -fi在我的 ARM mac 上完成后运行时brew install autoreconf,出现以下错误:
$ autoreconf -fi
Can't exec "aclocal": No such file or directory at /opt/homebrew/Cellar/autoconf/2.71/share/autoconf/Autom4te/FileUtils.pm line 274.
autoreconf: error: aclocal failed with exit status: 2
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我有很多.txt文件,其中包含多行和一列数据。但是,文件的长度是不一样的。有些文件有 2000 行,其他文件有 2001 行等等。
有时最后有一个空行,我想删除它。
我想将 0 行附加到除最长文件之外的所有文件的末尾,以便所有文件的行号相等。
我希望用一个简单的 shell 脚本来解决这个问题。