如果我有两个文件(单列),一个像这样(file1)
34
67
89
92
102
180
blue2
3454
Run Code Online (Sandbox Code Playgroud)
和第二个文件(file2)
23
56
67
69
102
200
Run Code Online (Sandbox Code Playgroud)
如何找到两个文件(交集)中共有的元素?此示例中的预期输出是
67
102
Run Code Online (Sandbox Code Playgroud)
请注意,每个文件中的项目(行)数不同。数字和字符串可以混合使用。它们可能不一定要排序。每个项目只出现一次。
根据以下一些答案进行时间检查。
# generate some data
>shuf -n2000000 -i1-2352452 > file1
>shuf -n2000000 -i1-2352452 > file2
#@ilkkachu
>time (join <(sort "file1") <(sort "file2") > out1)
real 0m15.391s
user 0m14.896s
sys 0m0.205s
>head out1
1
10
100
1000
1000001
#@Hauke
>time (grep -Fxf "file1" "file2" > out2)
real 0m7.652s
user 0m7.131s
sys 0m0.316s
>head out2
1047867
872652
1370463
189072 …Run Code Online (Sandbox Code Playgroud) 使用 运行 SLURM 作业时sbatch,slurm 会生成一个标准输出文件,看起来像 slurm-102432.out (slurm-jobid.out)。我想将此自定义为 (yyyymmddhhmmss-jobid-jobname.txt)。我该怎么做?
或者更一般地说,我如何在sbatch参数中包含计算变量-o?
我在我的 script.sh 中尝试了以下内容
#SBATCH -p core
#SBATCH -n 6
#SBATCH -t 1:00:00
#SBATCH -J indexing
#SBATCH -o "/home/user/slurm/$(date +%Y%m%d%H%M%S)-$(SLURM_JOB_ID)-indexing.txt"
Run Code Online (Sandbox Code Playgroud)
但这没有用。文件在新目录中的位置是正确的,但文件名只是文字 line $(date +%Y%m%d%H%M%S)-$(SLURM_JOB_ID)-indexing.txt。
所以,我正在寻找一种方法来将标准输出文件保存在/home/user/slurm/一个文件名如下的目录中:20160526093322-10453-indexing.txt
如果我有一个包含多行和多列 ( data.txt)的分隔文件:
346 dfd asw 34
565 sd wdew 34
667 ffg wew 23
473 sa as 21
533 jhf qwe 54
Run Code Online (Sandbox Code Playgroud)
和另一个我想提取行号的文件 ( positions.txt)
3
5
8
Run Code Online (Sandbox Code Playgroud)
如何使用该positions.txt文件从中提取这些位置data.txt?这是我对这个例子期望的结果:
667 ffg wew 23
533 jhf qwe 54
Run Code Online (Sandbox Code Playgroud) 例如,如果我在一个目录中有 n 个文件;
a
b
c
Run Code Online (Sandbox Code Playgroud)
如何将这些文件的成对组合(非定向)传递给函数?
预期的输出是
a-b
a-c
b-c
Run Code Online (Sandbox Code Playgroud)
以便它可以传递给像这样的函数
fn -file1 a -file2 b
fn -file1 a -file2 c
...
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在尝试的。
for i in *.txt
do
for j in *.txt
do
if [ "$i" != "$j" ]
then
echo "Pairs $i and $j"
fi
done
done
Run Code Online (Sandbox Code Playgroud)
输出
Pairs a.txt and b.txt
Pairs a.txt and c.txt
Pairs b.txt and a.txt
Pairs b.txt and c.txt
Pairs c.txt and a.txt
Pairs c.txt and b.txt
Run Code Online (Sandbox Code Playgroud)
我仍然有重复项(ab 与 ba 相同),我想也许有更好的方法来做到这一点。
我有一个包含字段的文件测试:cato和pos。
1 7100
1 35000
1 49321
1 49759
2 44842
2 52794
2 53558
3 53859
3 54013
3 55172
Run Code Online (Sandbox Code Playgroud)
我有一个包含字段的文件db:cato、start和stop。
1 6408 8000
1 11822 16373
1 18716 23389
1 27690 34330
1 36552 39191
1 39313 44565
2 44839 50247
2 60987 65017
2 65705 71523
Run Code Online (Sandbox Code Playgroud)
我的目标是在文件db中选择行,其中pos文件test 的字段落在文件db 的开始和停止范围内。存在匹配必须在cato组内发生的限制。这两个文件都按字段 1 …
我想在不下载的情况下验证 URL 是否存在。我在下面使用curl:
if [[ $(curl ftp://ftp.somewhere.com/bigfile.gz) ]] 2>/dev/null;
then
echo "This page exists."
else
echo "This page does not exist."
fi
Run Code Online (Sandbox Code Playgroud)
或使用wget:
if [[ $(wget ftp://ftp.somewhere.com/bigfile.gz) -O-]] 2>/dev/null;
then
echo "This page exists."
else
echo "This page does not exist."
fi
Run Code Online (Sandbox Code Playgroud)
如果 URL 不存在,这很有效。如果存在,它会下载文件。就我而言,文件非常大,我不想下载。我只想知道那个 URL 是否存在。