Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中复制文本文件中的文件名列表_Bash - Fatal编程技术网

在bash中复制文本文件中的文件名列表

在bash中复制文本文件中的文件名列表,bash,Bash,我需要复制文本文件中的文件名列表。通过以下方式进行尝试: #!/bin/sh mjdstart=55133 mjdend=56674 datadir=/nfs/m/ir1/ssc/evt hz="h" for mjd in $(seq $mjdstart $mjdend); do find $datadir/ssc"${hz}"_allcl_mjd"${mjd}".evt -maxdepth 1 -type f -printf $datadir'/%f\n' > ssc"${h

我需要复制文本文件中的文件名列表。通过以下方式进行尝试:

#!/bin/sh

mjdstart=55133
mjdend=56674
datadir=/nfs/m/ir1/ssc/evt
hz="h"

for mjd in $(seq $mjdstart $mjdend); do
    find $datadir/ssc"${hz}"_allcl_mjd"${mjd}".evt -maxdepth 1 -type f -printf $datadir'/%f\n' > ssc"${hz}".list
done
我也试过:

find $datadir/ssc"${hz}"_allcl_mjd"${mjd}".evt -maxdepth 1 -type f -printf $datadir'/%f\n' | split -l999 -d - ssc"${hz}".list
或者其他组合,但显然我遗漏了一些东西:文本文件是空的。我的错误在哪里?

请使用
>
(追加)而不是
(覆盖),否则您将只能输出最后一个命令:

> ssc"${hz}".list
for mjd in $(seq $mjdstart $mjdend); do
    find $datadir/ssc"${hz}"_allcl_mjd"${mjd}".evt -maxdepth 1 -type f -printf $datadir'/%f\n' >> ssc"${hz}".list
done

您使用的
find
错误。第一个参数是目录,它应该在其中搜索。此外,每次使用
都会覆盖列表文件。使用
>
连接:

find $datadir -maxdepth 1 -type f -name "src${hz}_allcl_mjd${mjd}.evt" >> ssc"${hz}".list

您不需要在此处使用
find
,因为您只需要检查一系列特定的文件名:

#!/bin/sh

mjdstart=55133
mjdend=56674
datadir=/nfs/m/ir1/ssc/evt
hz="h"

for mjd in $(seq $mjdstart $mjdend); do
    fnname="$datadir/ssc${hz}_allcl_mjd${mjd}.evt"
    [[ -f $fname ]] && printf "$fname\n"
done > "ssc$hz.list"

你说得对:我编辑了消息。
find
这里有点过头了:你运行一个外部程序只是为了查看一个文件是否存在。第一行做什么?第一行只是将输出文件截断为0字节。你说的
不起作用是什么意思?删除ssc“${hz}”。列出
部件并查看它打印的内容。还回显参数,以查看如果执行find时您的想法:
for…M;做回声。。。;完成
通过“不工作”我的意思是它不会在文本文件中写入文件名。对不起,我应该“回音”什么?这也是一个很好的解决方案+1你是说,在周期内,对吗?如何确保脚本看到这些文件?