【发布时间】:2020-12-14 16:56:48
【问题描述】:
我是批处理新手。我想遍历一个列表并使用输出内容替换另一个文件中的字符串。
ls -l somefile | grep .txt | awk 'print $4}' | while read file
do
toreplace="/Team/$file"
sed 's/dataFile/"$toreplace"/$file/ file2 > /tmp/test.txt
done
当我运行代码时出现错误
sed: 1: "s/dataFile/"$torepla ...": bad flag in substitute command: '$'
包含文件路径列表的 somefile 示例
foo/name/xxx/2020-01-01.txt
foo/name/xxx/2020-01-02.txt
foo/name/xxx/2020-01-03.txt
但是,我想要的输出是使用 somefile 目录中的文件路径列表来替换另一个 file2 内容中的字符串。像这样的:
This is the directory of locations where data from /Team/foo/name/xxx/2020-01-01.txt ............
【问题讨论】:
标签: linux bash automation batch-processing