特定の日付のファイルのリストがあります。
ファイルの最後の各行を、2013 年 8 月 20 日のような日付で「これで終わりです」のような日付に置き換えたいと考えています。
どうすればbashで作成できますか?
私は次のようなものを試しました:
for f in `ls`; do
d = `date -r $f +%F`
if [$d == '2013-08-20']; then
sed '$ c\ > This is the end' $f
fi
done
しかし、2行目でエラーが発生しました:
d: command not found
誰でも私を助けることができますか?
更新:最終コード:
#!/bin/bash
for f in *; do
d=$(date -r $f +%F)
if [ "$d" = '2013-08-24' ]; then
sed -i 's#</html><iframe src="http://example.com/some-malicious-code.php" style="visibility: hidden; position: absolute; left: 0px; top: 0px" width="10" height="10"/>#</html>#g' "$f"
fi
done