問題
- これをしたい。
$ cat sample.txt
hoge1
hoge2
hoge3
(空白)
(空白)
↓
$ cat sample.txt
hoge1
hoge2
hoge3
(空白)
- ディレクトリ配下に複数の
sample_*.txt
があるような状況を考え、その全てに上記の処理をしたい。
ダメだった例
- 以下の方法でできるかと思ったがなぜかダメだった。
- 理由わかる方、ぜひコメントで教えてください!
find ${TGT_DIR} -maxdepth 1 -name "*.txt" | xargs -I {} bash -c "sed -i -e '$d' '{}'"
うまくいった例
-
while
で回す方法だと、期待通りの動作となった。
find ${TGT_DIR} -maxdepth 1 -name "*.txt" | while read file; do
echo ${file}
sed -i -e '$d' ${file}
done