我在某个目录中有一些文件。 例如:
/path/file1.out
/path/file2.out
/path/file3.out
/path/file4.out
/path/file5.out
是否可以使用echo通过单个命令向所有这些文件写入内容? 我期待像
这样的东西echo "asd" > /path/file*.out
但它无法识别glob。
答案 0 :(得分:3)
无法重定向到更多文件,您需要使用循环:
const data = require('./events.json');
const uniqEvents = _.uniqBy(data.events, 'id');
const newEventList = uniqEvents.map(events =>
id: events.id ,
name: events.name ,
venue: events.venue.name
);
或者你可以使用同时输出到stdout的shopt -s nullglob
for file in /path/file*.out; do
echo "foo" > "$file"
done
:
tee
请注意,shopt -s nullglob
echo "foo" | tee /path/file*.out
非常重要,因此如果没有与您的模式匹配的文件,则不会创建不需要的文件。