複数ファイルの内容の変更

複数ファイルの内容の変更

次の内容を含むlist.txtというファイルがあります。

paswd.c
acnt.c
control.c
... 

(残りは省略)

擬似コードと同じことをしたいのですが。

point to first line of list.txt;
while (list.txt not reaching end of file)
{
    get string from line;
    find -name 'string';
    if (find)
    {
        delete first 7 lines in file;
    }
    advance one line;
}

私は労働組合を信じる探すパラメータそしてsedこれは達成することができる。

ベストアンサー1

次のことを試してみてください。

$ xargs -a list.txt -I myfilename find . -name myfilename -exec sed 1,7d '{}' \;
  • xargs は list.txt のファイル名を読み込み、myfilenameパターンを find コマンドで読み取ったファイル名に置き換えます。
  • findはファイルを見つけてsedに渡し、最初の7行を削除します(7行未満の場合はファイルを空にします)。

おすすめ記事