특정 문자 시퀀스를 사용하여 파일을 분할하고 소스 파일에서 파일 이름을 추출합니다.

특정 문자 시퀀스를 사용하여 파일을 분할하고 소스 파일에서 파일 이름을 추출합니다.

큰 파일(.sdf)이 있고 특수 문자($$$$ 찾기)를 사용하여 더 작은 파일로 분할하고 싶습니다.

sdf 파일은 다음과 같습니다.

vercirnon
 OpenBabel12162112363D

 30 32  0  0  0  0  0  0  0  0999 V2000
    9.5587    8.0626    0.2010 C   0  0  0  0  0  0  0  0  0  0  0  0
    9.5370    6.8058   -0.7024 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.9692    7.2294   -2.0790 C   0  0  0  0  0  0  0  0  0  0  0  0
   10.9840    6.3066   -0.9295 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.7040    5.7067   -0.0175 C   0  0  0  0  0  0  0  0  0  0  0  0
    9.1113    5.2073    1.2337 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.3733    4.2234    1.8957 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.2091    3.7212    1.3148 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.2780    2.4897    2.2251 S   0  0  0  0  0  0  0  0  0  0  0  0
    6.8993    1.1790    2.0362 O   0  0  0  0  0  0  0  0  0  0  0  0
    5.8588    2.9960    3.5333 O   0  0  0  0  0  0  0  0  0  0  0  0
    4.9981    2.2950    1.5012 N   0  0  0  0  0  0  0  0  0  0  0  0
    3.8722    3.1731    1.3833 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.9973    4.5103    1.8031 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.9406    5.4112    1.6839 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.7284    4.9785    1.1608 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.3923    6.0759    1.0574 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    1.5746    3.6564    0.7477 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.6388    2.7433    0.8212 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.4135    1.3214    0.4021 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1426    0.4511    0.8208 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.2975    0.9364   -0.5087 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.5786    1.7825   -1.3567 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.4392    1.2632   -2.1615 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7443   -0.0390   -2.1595 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.6669   -0.4714   -2.8846 O   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0490   -0.8769   -1.3832 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9865   -0.4274   -0.5611 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.7891    4.1887    0.0683 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.5337    5.1733   -0.5887 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  2  3  1  0  0  0  0
  2  4  1  0  0  0  0
  2  5  1  0  0  0  0
  5  6  2  0  0  0  0
  5 30  1  0  0  0  0
  6  7  1  0  0  0  0
  7  8  2  0  0  0  0
  8  9  1  0  0  0  0
  8 29  1  0  0  0  0
  9 10  2  0  0  0  0
  9 11  2  0  0  0  0
  9 12  1  0  0  0  0
 12 13  1  0  0  0  0
 13 14  2  0  0  0  0
 13 19  1  0  0  0  0
 14 15  1  0  0  0  0
 15 16  2  0  0  0  0
 16 17  1  0  0  0  0
 16 18  1  0  0  0  0
 18 19  2  0  0  0  0
 19 20  1  0  0  0  0
 20 21  2  0  0  0  0
 20 22  1  0  0  0  0
 22 23  1  0  0  0  0
 22 28  1  0  0  0  0
 23 24  1  0  0  0  0
 24 25  1  0  0  0  0
 25 26  1  0  0  0  0
 25 27  1  0  0  0  0
 27 28  1  0  0  0  0
 29 30  2  0  0  0  0
M  END
$$$$
BMCL2016_20
 OpenBabel12162112363D

 27 30  0  0  0  0  0  0  0  0999 V2000
    1.7921    2.8234   -0.2356 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1990    2.7653    0.4098 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.7558    1.3491    0.1528 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2150    0.2459    0.8374 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.7062   -1.0464    0.6362 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.7583   -1.2832   -0.2567 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.2901   -2.6928   -0.4837 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.1934   -3.6802   -0.7756 N   0  3  0  0  0  0  0  0  0  0  0  0
    3.6094   -3.8094   -1.9125 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.8079   -3.1344   -3.2109 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.6857   -2.3007   -3.2802 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.0661   -3.4129   -4.3038 O   0  0  0  0  0  0  0  0  0  0  0  0
    2.6185   -4.7945   -1.8075 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.6833   -5.2233   -0.4919 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.9431   -6.1495    0.1174 N   0  0  0  0  0  0  0  0  0  0  0  0
    2.2260   -6.3518    1.4133 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2272   -5.6463    2.0980 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.5189   -5.9726    3.7741 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    3.9903   -4.6817    1.4401 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.6977   -4.4753    0.0988 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.3011   -0.1919   -0.9458 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.8099    1.1011   -0.7442 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1193    3.0497    1.9295 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.7571    4.5058    2.2596 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.6882    5.3885    1.6530 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.6783    5.2898    0.2371 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.0923    3.8800   -0.1877 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  2  3  1  0  0  0  0
  2 23  1  0  0  0  0
  2 27  1  0  0  0  0
  3  4  2  0  0  0  0
  3 22  1  0  0  0  0
  4  5  1  0  0  0  0
  5  6  2  0  0  0  0
  6  7  1  0  0  0  0
  6 21  1  0  0  0  0
  7  8  1  0  0  0  0
  8  9  2  0  0  0  0
  8 20  1  0  0  0  0
  9 10  1  0  0  0  0
  9 13  1  0  0  0  0
 10 11  2  0  0  0  0
 10 12  1  0  0  0  0
 13 14  2  0  0  0  0
 14 15  1  0  0  0  0
 14 20  1  0  0  0  0
 15 16  1  0  0  0  0
 16 17  2  0  0  0  0
 17 18  1  0  0  0  0
 17 19  1  0  0  0  0
 19 20  2  0  0  0  0
 21 22  2  0  0  0  0
 23 24  1  0  0  0  0
 24 25  1  0  0  0  0
 25 26  1  0  0  0  0
 26 27  1  0  0  0  0
M  CHG  1   8   1
M  END
$$$$
BMCL2016_19
 OpenBabel12162112363D

 24 26  0  0  0  0  0  0  0  0999 V2000
    7.4483    1.0368    0.6595 O   0  0  0  0  0  0  0  0  0  0  0  0
    8.0491    0.0940    1.1188 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.7614    0.3379    2.0658 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.9192   -1.2687    0.5814 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.5726   -2.3934    1.0856 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.1380   -3.4812    0.3334 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.4995   -4.8363    0.4795 N   0  0  0  0  0  0  0  0  0  0  0  0
    7.8411   -5.6890   -0.4439 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.9259   -5.2387   -1.3981 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.1791   -6.3752   -2.4701 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    6.6087   -3.8841   -1.4962 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.2318   -3.0081   -0.6162 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.1404   -1.6587   -0.4670 N   0  3  0  0  0  0  0  0  0  0  0  0
    6.2065   -0.8240   -1.2132 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.8399   -0.6829   -0.5536 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.5003   -1.3309    0.6427 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2340   -1.1639    1.2097 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.2730   -0.3639    0.5911 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9259   -0.1249    1.2502 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9644   -0.2517    2.6331 F   0  0  0  0  0  0  0  0  0  0  0  0
    0.4125    1.1039    0.9805 F   0  0  0  0  0  0  0  0  0  0  0  0
    0.0346   -1.0091    0.8151 F   0  0  0  0  0  0  0  0  0  0  0  0
    2.6134    0.3005   -0.5873 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.8777    0.1379   -1.1594 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  2  0  0  0  0
  2  3  1  0  0  0  0
  2  4  1  0  0  0  0
  4  5  1  0  0  0  0
  4 13  2  0  0  0  0
  5  6  2  0  0  0  0
  6  7  1  0  0  0  0
  6 12  1  0  0  0  0
  7  8  1  0  0  0  0
  8  9  2  0  0  0  0
  9 10  1  0  0  0  0
  9 11  1  0  0  0  0
 11 12  2  0  0  0  0
 12 13  1  0  0  0  0
 13 14  1  0  0  0  0
 14 15  1  0  0  0  0
 15 16  2  0  0  0  0
 15 24  1  0  0  0  0
 16 17  1  0  0  0  0
 17 18  2  0  0  0  0
 18 19  1  0  0  0  0
 18 23  1  0  0  0  0
 19 20  1  0  0  0  0
 19 21  1  0  0  0  0
 19 22  1  0  0  0  0
 23 24  2  0  0  0  0
M  CHG  1  13   1
M  END

이 파일을 $$$$ 문자를 사용하여 분할한 다음 삭제하고 싶습니다. 또한 새 파일의 이름은 첫 번째 줄(이름)과 확장자를 사용하여 바꿔야 합니다 .sdf. 결과는 다음과 같아야 합니다.

파일 1 =vercirnon.sdf

vercirnon
 OpenBabel12162112363D

 30 32  0  0  0  0  0  0  0  0999 V2000
    9.5587    8.0626    0.2010 C   0  0  0  0  0  0  0  0  0  0  0  0
    9.5370    6.8058   -0.7024 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.9692    7.2294   -2.0790 C   0  0  0  0  0  0  0  0  0  0  0  0
   10.9840    6.3066   -0.9295 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.7040    5.7067   -0.0175 C   0  0  0  0  0  0  0  0  0  0  0  0
    9.1113    5.2073    1.2337 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.3733    4.2234    1.8957 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.2091    3.7212    1.3148 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.2780    2.4897    2.2251 S   0  0  0  0  0  0  0  0  0  0  0  0
    6.8993    1.1790    2.0362 O   0  0  0  0  0  0  0  0  0  0  0  0
    5.8588    2.9960    3.5333 O   0  0  0  0  0  0  0  0  0  0  0  0
    4.9981    2.2950    1.5012 N   0  0  0  0  0  0  0  0  0  0  0  0
    3.8722    3.1731    1.3833 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.9973    4.5103    1.8031 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.9406    5.4112    1.6839 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.7284    4.9785    1.1608 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.3923    6.0759    1.0574 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    1.5746    3.6564    0.7477 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.6388    2.7433    0.8212 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.4135    1.3214    0.4021 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1426    0.4511    0.8208 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.2975    0.9364   -0.5087 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.5786    1.7825   -1.3567 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.4392    1.2632   -2.1615 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7443   -0.0390   -2.1595 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.6669   -0.4714   -2.8846 O   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0490   -0.8769   -1.3832 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9865   -0.4274   -0.5611 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.7891    4.1887    0.0683 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.5337    5.1733   -0.5887 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  2  3  1  0  0  0  0
  2  4  1  0  0  0  0
  2  5  1  0  0  0  0
  5  6  2  0  0  0  0
  5 30  1  0  0  0  0
  6  7  1  0  0  0  0
  7  8  2  0  0  0  0
  8  9  1  0  0  0  0
  8 29  1  0  0  0  0
  9 10  2  0  0  0  0
  9 11  2  0  0  0  0
  9 12  1  0  0  0  0
 12 13  1  0  0  0  0
 13 14  2  0  0  0  0
 13 19  1  0  0  0  0
 14 15  1  0  0  0  0
 15 16  2  0  0  0  0
 16 17  1  0  0  0  0
 16 18  1  0  0  0  0
 18 19  2  0  0  0  0
 19 20  1  0  0  0  0
 20 21  2  0  0  0  0
 20 22  1  0  0  0  0
 22 23  1  0  0  0  0
 22 28  1  0  0  0  0
 23 24  1  0  0  0  0
 24 25  1  0  0  0  0
 25 26  1  0  0  0  0
 25 27  1  0  0  0  0
 27 28  1  0  0  0  0
 29 30  2  0  0  0  0
M  END

파일 2=BMCL2016_20.sdf

 BMCL2016_20
 OpenBabel12162112363D

 27 30  0  0  0  0  0  0  0  0999 V2000
    1.7921    2.8234   -0.2356 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1990    2.7653    0.4098 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.7558    1.3491    0.1528 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2150    0.2459    0.8374 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.7062   -1.0464    0.6362 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.7583   -1.2832   -0.2567 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.2901   -2.6928   -0.4837 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.1934   -3.6802   -0.7756 N   0  3  0  0  0  0  0  0  0  0  0  0
    3.6094   -3.8094   -1.9125 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.8079   -3.1344   -3.2109 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.6857   -2.3007   -3.2802 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.0661   -3.4129   -4.3038 O   0  0  0  0  0  0  0  0  0  0  0  0
    2.6185   -4.7945   -1.8075 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.6833   -5.2233   -0.4919 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.9431   -6.1495    0.1174 N   0  0  0  0  0  0  0  0  0  0  0  0
    2.2260   -6.3518    1.4133 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2272   -5.6463    2.0980 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.5189   -5.9726    3.7741 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    3.9903   -4.6817    1.4401 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.6977   -4.4753    0.0988 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.3011   -0.1919   -0.9458 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.8099    1.1011   -0.7442 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.1193    3.0497    1.9295 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.7571    4.5058    2.2596 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.6882    5.3885    1.6530 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.6783    5.2898    0.2371 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.0923    3.8800   -0.1877 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  2  3  1  0  0  0  0
  2 23  1  0  0  0  0
  2 27  1  0  0  0  0
  3  4  2  0  0  0  0
  3 22  1  0  0  0  0
  4  5  1  0  0  0  0
  5  6  2  0  0  0  0
  6  7  1  0  0  0  0
  6 21  1  0  0  0  0
  7  8  1  0  0  0  0
  8  9  2  0  0  0  0
  8 20  1  0  0  0  0
  9 10  1  0  0  0  0
  9 13  1  0  0  0  0
 10 11  2  0  0  0  0
 10 12  1  0  0  0  0
 13 14  2  0  0  0  0
 14 15  1  0  0  0  0
 14 20  1  0  0  0  0
 15 16  1  0  0  0  0
 16 17  2  0  0  0  0
 17 18  1  0  0  0  0
 17 19  1  0  0  0  0
 19 20  2  0  0  0  0
 21 22  2  0  0  0  0
 23 24  1  0  0  0  0
 24 25  1  0  0  0  0
 25 26  1  0  0  0  0
 26 27  1  0  0  0  0
M  CHG  1   8   1
M  END

파일 3 =BMCL2016_19.sdf

    BMCL2016_19
 OpenBabel12162112363D

 24 26  0  0  0  0  0  0  0  0999 V2000
    7.4483    1.0368    0.6595 O   0  0  0  0  0  0  0  0  0  0  0  0
    8.0491    0.0940    1.1188 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.7614    0.3379    2.0658 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.9192   -1.2687    0.5814 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.5726   -2.3934    1.0856 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.1380   -3.4812    0.3334 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.4995   -4.8363    0.4795 N   0  0  0  0  0  0  0  0  0  0  0  0
    7.8411   -5.6890   -0.4439 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.9259   -5.2387   -1.3981 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.1791   -6.3752   -2.4701 Cl  0  0  0  0  0  0  0  0  0  0  0  0
    6.6087   -3.8841   -1.4962 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.2318   -3.0081   -0.6162 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.1404   -1.6587   -0.4670 N   0  3  0  0  0  0  0  0  0  0  0  0
    6.2065   -0.8240   -1.2132 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.8399   -0.6829   -0.5536 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.5003   -1.3309    0.6427 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.2340   -1.1639    1.2097 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.2730   -0.3639    0.5911 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9259   -0.1249    1.2502 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.9644   -0.2517    2.6331 F   0  0  0  0  0  0  0  0  0  0  0  0
    0.4125    1.1039    0.9805 F   0  0  0  0  0  0  0  0  0  0  0  0
    0.0346   -1.0091    0.8151 F   0  0  0  0  0  0  0  0  0  0  0  0
    2.6134    0.3005   -0.5873 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.8777    0.1379   -1.1594 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  2  0  0  0  0
  2  3  1  0  0  0  0
  2  4  1  0  0  0  0
  4  5  1  0  0  0  0
  4 13  2  0  0  0  0
  5  6  2  0  0  0  0
  6  7  1  0  0  0  0
  6 12  1  0  0  0  0
  7  8  1  0  0  0  0
  8  9  2  0  0  0  0
  9 10  1  0  0  0  0
  9 11  1  0  0  0  0
 11 12  2  0  0  0  0
 12 13  1  0  0  0  0
 13 14  1  0  0  0  0
 14 15  1  0  0  0  0
 15 16  2  0  0  0  0
 15 24  1  0  0  0  0
 16 17  1  0  0  0  0
 17 18  2  0  0  0  0
 18 19  1  0  0  0  0
 18 23  1  0  0  0  0
 19 20  1  0  0  0  0
 19 21  1  0  0  0  0
 19 22  1  0  0  0  0
 23 24  2  0  0  0  0
M  CHG  1  13   1
M  END

누군가 이 작업을 수행하기 위한 몇 가지 코드를 제안할 수 있습니까? 비슷한 것을 찾았지만 아무것도 찾지 못했습니다.

미리 감사드립니다.

답변1

csplit분할 모드를 허용하고 xxii(텍스트 xxii=증가 숫자)라는 이름의 (기본) 파일을 만듭니다. 다음 단계는 파일을 반복하고 해당 첫 번째 줄로 이름을 바꾸고 원본 파일을 삭제하는 것입니다.

#/bin/bash
csplit --suppress-matched infile.sdf '/\$\$\$\$/' '{*}' &&
for file in xx* ; do
  mv "$file" "$(head -n1 "$file")".sdf
done &&
rm infile.sdf

답변2

다음과 같이 시도해 보세요.

$ perl -lne '
    if (/^\s*\$\$\$\$\s*$/) {
      $newfile = 1;
      next;
    };

    if ($. == 1 || $newfile) {
      open($FH, ">", "$_.sdf") || die "error opening $_.sdf for write: $!\n";
      $newfile = 0;
    }

    print $FH $_;
    close(ARGV) if eof' bigfile.sdf

이 변수는 $newfile출력 파일 이름이 입력에서 추출되어 쓰기 위해 열리는지 여부를 결정하는 부울 플래그로 사용됩니다. $newfile입력 파일의 첫 번째 줄과 일치하는 줄 뒤의 각 줄에 대해 true입니다 $$$$(줄에 있을 수 있는 선행 및/또는 후행 공백 무시). 나머지 시간에는 거짓입니다.

이 줄은 각 입력 파일의 끝에서 close(ARGV) if eof줄 카운터( )를 재설정하여 스크립트가 여러 입력 파일을 처리할 수 있도록 합니다.$.

참고: 입력에 대한 온전성 검사는 없습니다. 이 스크립트는 파일의 첫 번째 줄과 그 뒤의 첫 번째 줄만 $$$$유효한 파일 이름이라고 믿는 매우 기본적인 빠르고 더러운 해킹입니다. 쓰기 위해 파일을 여는 동안 오류가 발생하는 경우(예: "권한이 거부됨", "장치에 남은 공간 없음" 또는 기타 오류로 인해) 적어도 정상적으로 종료되고 오류 메시지가 표시됩니다.

답변3

awk '
NR == 1         {filename = $0 ".sdf"}
/^\$\$\$\$$/    {getline; filename = $0 ".sdf"}
                {print > filename}
' file.sdf

패턴에서 특수 문자를 이스케이프해야 합니다.\$

관련 정보