200,000を超えるファイルにテキストを追加したいです。今しようとしています。
find . -name *.txt -print | xargs -I % echo "hello world" >> %
しかし、何も起こりませんでした。実行するとfind . -name *.txt
自然になりました。echo "hello world" >> myfile.txt
ベストアンサー1
シェルは見る>> %
前に部品をxargs
拡張しています。
シェルリダイレクトを実行する必要がある場合は、次のことを試してください。
find . -name "*.txt" -exec sh -c '
echo "hello world" >> "$0"
' {} \;
仕組み:
find
{}
一致するすべてのファイルに置き換えるbash -c "some command" arg0...
$0...
スクリプト内で設定"some command"
sed
>>
または、たとえば、依存しないコマンドを使用できます。
find . -name "*.txt" -exec sed -i -e '$a\
hello world' {} \;
引用: