
ファイルから部分行をコピーし、それを追加のテキスト(他の変数を含む)で他のファイルに追加するbashスクリプトの要件があります。
はい
ファイル1.txtコンテンツ
Warning: pasting the following URL into your browser exposes the OTP secret to Google:
https://www.google.com/chartxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Your new secret key is: xxxxxxxxxxxxxxxxxxxxxx
Your verification code is xxxxxx
Your emergency scratch codes are:
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
だから、パスワードをコピーして別のファイルに貼り付けるだけです。
ファイル2.txt
secret code of user xxxxxxxxxxx is saved
私はLinuxとスクリプトに初めて触れたので、助けてくれてありがとう。
また、私の質問が不明な場合はお知らせください。
答え1
このsedを試してください:
sed -n 's|Your new secret key is: \(.*\)|secret code of user \1 is saved|p' File1.txt >> File2.txt
File1.txt
にパスワードを追加しますFile2.txt
。パスワード.*
はで一致してコピーされます\1
。