Bash:検索パターンに基づいて複数のログファイル構成を結合する

Bash:検索パターンに基づいて複数のログファイル構成を結合する

多くのtxtファイルを含むフォルダがあります。各ファイルは次の形式で存在します。

Allowed overlap: -3
H-bond overlap reduction: 0.4
Ignore contacts between atoms separated by 4 bonds or less
Detect intra-residue contacts: False
Detect intra-molecule contacts: False

19 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

私の目標:フォルダ内のファイルを繰り返してそれらを組み合わせてグローバル出力にすることです。例では、「19(この数字はファイルごとに異なる)連絡先」の後の文字列のみを考慮して、ファイルの最初の6行をスキップしたいことに注意する必要があります。

実装に可能なワークフロー:

# make a log file which will contain info from all files going to be looped on the next step.
echo "This is a beginning of the global output" > ./final_output.txt
# that is a key phrase which is the indicator of the first string which should be taken from each of the files
key= "#any of the digit# contacts" 

#now I want to loop each of the files with the aim to add all of the strings after (and including) ${key} to the final_output.txt
for file in ${folder}/*.txt; do
  file_title=$(basename "$file")
  # 1- print the ${file_title} within the final_output.txt
  # 2 -  add all of the strings from the file into the final_output.txt
  # NB ! I need to take only the strings after (and including) the key-phrace

done

答え1

3つのファイルを例に挙げます。

ファイル1

Allowed overlap: -3
H-bond overlap reduction: 0.4
Ignore contacts between atoms separated by 4 bonds or less
Detect intra-residue contacts: False
Detect intra-molecule contacts: False

19 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

ファイル3

Allowed overlap: -3
H-bond overlap reduction: 0.4
Ignore contacts between atoms separated by 4 bonds or less
Detect intra-residue contacts: False
Detect intra-molecule contacts: False

17 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

ファイル4

Allowed overlap: -3
H-bond overlap reduction: 0.4
Ignore contacts between atoms separated by 4 bonds or less
Detect intra-residue contacts: False
Detect intra-molecule contacts: False

12 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

次のコードは、19の連絡先、17の連絡先、12の連絡先の出力をファイルの最後まで保存します。

 for i in file1 file3 file4; do sed -n '/^[0-9]/,$p'  $i; done > /var/tmp/outputfile.txt

出力

19 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335
17 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335
12 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

答え2

同じ入力ファイルを使用して別の方法を見つけました。

パスワード:

 for i in file1 file3 file4; do sed '1,6d'  $i; done > /var/tmp/outputfile.txt

出力

19 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335
17 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335
12 contacts
atom1  atom2  overlap  distance
:128.B@BB  :300.C@BB  -1.676  4.996
:179.B@BB  :17.C@BB   -1.898  5.218
:182.B@BB  :17.C@BB   -2.015  5.335

関連情報