#!/bin/sh
for line in $(cat all_files.txt)
do
if [ -f "$line" ]; #A folder like /tmp/a/b is also true for -e, there is a whitespace before and after "-f".
then
sed 's/abc/def/g' $line >> ${line%.*}.$(date +%Y_%M_%d).fix #
else
echo "$line" >> files_not_found.txt
fi
done
shell读取文件的一个更加高效的方法,有两个优势:1.不用创建管道;2.不用开启cat进程。
<pre name="code" class="java">while read -r line
do
echo $line
done < all_files.txt