问题描述
FreeBSD 9.2 RELEASE p2
我有一个文件 fromdirs.txt
。在这个文件是一个新的行分隔目录列表如下所示:
/ etc
/ home
/ home / goods /
我需要先在所有目录的文件中找到good包含字符串(NODES_'TASK),然后将所有这些文件复制到目录 / tmp
。
2.sh file chmod + x and 755
fromDirs.txt file chmod + x and is 755
这段代码给我错误
IFS = $'\\\
'read -d''-r -a dirs< fromDirs.txt
find$ {dirs [@]}-type f \(-name'* good *'-o -exec grep -F(NODES_'TASK'){} \; \)-exec cp {} / tmp / \;
2.sh:无法打开fromDirs.txt:没有这样的文件或目录
$ b 2.sh:$ {dirs [...}:错误的替换
但是,文件fromDirs.txt存在,并从它的分配目录运行2.sh,我也想提供完整的路径,而不是fromDirs.txt和错误相同
这段代码给我错误
$ $ p $ $ $ c $ FI $ = read -r dirs
do
找到$ dirs-type f \(-name'* good *'-o -exec grep -F(NODES_'TASK'){} \ ; \)-exec cp {} / tmp / \;
完成< $ FILE
2.sh:6:语法错误:期待做)
这段代码也给我错误
FILENAME = fromDirs.txt
$ b $ awk'{kount ++; print kount,$ 0}
END {print\\\
Totalkount行读取}$ FILENAME
2.sh::未找到awk:无法从Dirs.txt打开文件源代码行号2
那么如何逐行读取文件并执行我所需要的操作?
这适用于我
用于cat fromDirs.txt中的行找到$ line-type f \(-name'* good *'-o -exec grep -F(NODES_'TASK'){} \; \)-exec cp {} / tmp / \ ;;完成
FreeBSD 9.2 RELEASE p2
I have a file fromdirs.txt
. In this file is a new line separated directory list like so:
/etc
/home
/home/goods/
I need to first find in all directory's files which have names like "good" or contain string "(NODES_'TASK')" and then copy all these files into the directory /tmp
.
2.sh file chmod +x and is 755fromDirs.txt file chmod +x and is 755
This code give me error
IFS=$'\n' read -d '' -r -a dirs < fromDirs.txt
find "${dirs[@]}" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/ \;
2.sh: cannot open fromDirs.txt : No such file or directory
2.sh: ${dirs[...}: Bad substitution
But File fromDirs.txt exist and 2.sh running from it allocation directory, also i trying to provide full path instead of fromDirs.txt and error the same
This code give me error
FILE=fromDirs.txt
IFS='\n'
while read -r dirs
do
find "$dirs" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/ \;
done < "$FILE"
2.sh: 6: Syntax error: "done" unexpected (expecting "do")
This code give me error too
FILENAME=fromDirs.txt
awk '{kount++;print kount, $0}
END{print "\nTotal " kount " lines read"}' $FILENAME
2.sh: : not found awk: can't open file fromDirs.txt source line number 2
So how to read file line by line and do what i need?
This works for me
for line in "`cat fromDirs.txt`"; do find "$line" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/ \;; done
这篇关于在文件列表中找到多个目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!