[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理如何合并这样的txt文本?

各位前辈,你们好!
在下最近使用一款软件来处理科学数据,然后得到一系列txt文件,每个txt文件里都有

Note: Orbital   105 is HOMO, energy:   -0.277311 a.u.   -7.546013 eV
       Orbital   106 is LUMO, energy:   -0.022027 a.u.   -0.599384 eV
       HOMO-LUMO gap:    0.255284 a.u.    6.946629 eV    670.247947 kJ/mol

这样三行数据,数据内容不同,数据所处的行数也不同,但都是“Note”开头的。我想把各个txt里的这三行内容汇总到一个txt文件里,并在各个行之前添加对应txt文件名,请问该如何做到?

例如我有一系列txt文件,abc.txt ABC.txt 123.txt,我想得到的新txt内容为:

abc
Note: Orbital   105 is HOMO, energy:   -0.277311 a.u.   -7.546013 eV
       Orbital   106 is LUMO, energy:   -0.022027 a.u.   -0.599384 eV
       HOMO-LUMO gap:    0.255284 a.u.    6.946629 eV    670.247947 kJ/mol

ABC
Note: Orbital   105 is HOMO, energy:   -0.277311 a.u.   -7.546013 eV
       Orbital   106 is LUMO, energy:   -0.022027 a.u.   -0.599384 eV
       HOMO-LUMO gap:    0.255284 a.u.    6.946629 eV    670.247947 kJ/mol

123
Note: Orbital   105 is HOMO, energy:   -0.277311 a.u.   -7.546013 eV
       Orbital   106 is LUMO, energy:   -0.022027 a.u.   -0.599384 eV
       HOMO-LUMO gap:    0.255284 a.u.    6.946629 eV    670.247947 kJ/mol







完整的txt内容如下:

Multiwfn -- A Multifunctional Wavefunction Analyzer
Version 3.7(dev), release date: 2019-Nov-1
Project leader: Tian Lu (Beijing Kein Research Center for Natural Sciences)
Below paper ***MUST BE CITED*** if Multiwfn is utilized in your work:
          Tian Lu, Feiwu Chen, J. Comput. Chem., 33, 580-592 (2012)
Multiwfn official website: http://sobereva.com/multiwfn
Multiwfn English forum: http://sobereva.com/wfnbbs
Multiwfn Chinese forum: http://bbs.keinsci.com/wfn

( The number of threads:  8   Current date: 2019-11-19   Time: 09:55:42 )

Please wait...
Loading various information of the wavefunction
The highest angular moment basis functions is D
Loading basis set definition...
Loading orbitals...
Converting basis function information to GTF information...
Generating overlap matrix...
Back converting basis function information from Cartesian to spherical type...
Generating density matrix based on SCF orbitals...

Total/Alpha/Beta electrons:    210.0000    105.0000    105.0000
Net charge:     0.00000      Expected multiplicity:    1
Atoms:     26,  Basis functions:    476,  GTFs:    846
Total energy:   -2115.836188993044 Hartree,   Virial ratio:  2.00238388
This is a restricted single-determinant wavefunction
Orbitals from 1 to   105 are occupied
Title line of this file: Title Card Required

Loaded ABCD_AAA.fchk successfully!
Formula: S8 N2 Cl15 Cs1
Molecule weight:       666.02019
Point group: F4

                    ************ Main function menu ************
0 Show molecular structure and view orbitals
1 Output all properties at a point
2 Topology analysis
3 Output and plot specific property in a line
4 Output and plot specific property in a plane
5 Output and plot specific property within a spatial region (calc. grid data)
6 Check & modify wavefunction
7 Population analysis and atomic charges
8 Orbital composition analysis
9 Bond order analysis
10 Plot total DOS, partial DOS, OPDOS, local DOS and photoelectron spectrum
11 Plot IR/Raman/UV-Vis/ECD/VCD/ROA spectrum
12 Quantitative analysis of molecular surface
13 Process grid data (No grid data is presented currently)
14 Adaptive natural density partitioning (AdNDP) analysis
15 Fuzzy atomic space analysis
16 Charge decomposition analysis (CDA) and extended CDA (ECDA)
17 Basin analysis
18 Electron excitation analysis
19 Orbital localization analysis
20 Visual study of weak interaction
21 Energy decomposition analysis
100 Other functions (Part 1)        200 Other functions (Part 2)
Nucleus list:
    1(O ) --> Charge:  8.000000  x,y,z(Bohr):  -8.929672   2.024485   1.004248
    2(O ) --> Charge:  8.000000  x,y,z(Bohr):  -9.763455  -1.109600  -1.832432
    3(C ) --> Charge:  6.000000  x,y,z(Bohr):  -8.460157   0.006185  -0.174519
    4(Na) --> Charge: 11.000000  x,y,z(Bohr): -12.612463   2.160224  -1.450064
    5(F ) --> Charge:  9.000000  x,y,z(Bohr):   1.022313   2.849331  -0.896200
    6(F ) --> Charge:  9.000000  x,y,z(Bohr):   1.545568   1.347049   2.938965
    7(F ) --> Charge:  9.000000  x,y,z(Bohr):  -0.779625  -2.267522  -2.106199
    8(F ) --> Charge:  9.000000  x,y,z(Bohr):  -0.967032  -2.765132   2.013891
    9(F ) --> Charge:  9.000000  x,y,z(Bohr):   3.931592  -2.967363   0.401992
   10(F ) --> Charge:  9.000000  x,y,z(Bohr):   4.014622  -0.487438  -2.933183
   11(F ) --> Charge:  9.000000  x,y,z(Bohr):  -3.459239   2.188040   2.000752
   12(F ) --> Charge:  9.000000  x,y,z(Bohr):  -3.849666   1.587675  -2.090582
   13(F ) --> Charge:  9.000000  x,y,z(Bohr):   6.040311   3.320623   0.556040
   14(F ) --> Charge:  9.000000  x,y,z(Bohr):   6.588591   0.117457   3.138778
   15(F ) --> Charge:  9.000000  x,y,z(Bohr):  -6.040318  -1.899865   3.118696
   16(F ) --> Charge:  9.000000  x,y,z(Bohr):  -5.565383  -3.497473  -0.682380
   17(F ) --> Charge:  9.000000  x,y,z(Bohr):  10.788740   0.750137   0.650052
   18(F ) --> Charge:  9.000000  x,y,z(Bohr):   8.902838   1.282742  -2.954838
   19(F ) --> Charge:  9.000000  x,y,z(Bohr):   8.911750  -2.416307  -1.162048
   20(C ) --> Charge:  6.000000  x,y,z(Bohr):   1.360199   0.719358   0.471219
   21(C ) --> Charge:  6.000000  x,y,z(Bohr):  -0.992835  -1.041976   0.128758
   22(C ) --> Charge:  6.000000  x,y,z(Bohr):   3.903294  -0.540107  -0.383137
   23(C ) --> Charge:  6.000000  x,y,z(Bohr):  -3.574751   0.406503   0.173193
   24(C ) --> Charge:  6.000000  x,y,z(Bohr):   6.317275   0.787373   0.696559
   25(C ) --> Charge:  6.000000  x,y,z(Bohr):  -5.930502  -1.306092   0.602564
   26(C ) --> Charge:  6.000000  x,y,z(Bohr):   8.796903   0.075567  -0.742547
Note: Orbital   105 is HOMO, energy:   -0.277311 a.u.   -7.546013 eV
       Orbital   106 is LUMO, energy:   -0.022027 a.u.   -0.599384 eV
       HOMO-LUMO gap:    0.255284 a.u.    6.946629 eV    670.247947 kJ/mol

                    ************ Main function menu ************
0 Show molecular structure and view orbitals
1 Output all properties at a point
2 Topology analysis
3 Output and plot specific property in a line
4 Output and plot specific property in a plane
5 Output and plot specific property within a spatial region (calc. grid data)
6 Check & modify wavefunction
7 Population analysis and atomic charges
8 Orbital composition analysis
9 Bond order analysis
10 Plot total DOS, partial DOS, OPDOS, local DOS and photoelectron spectrum
11 Plot IR/Raman/UV-Vis/ECD/VCD/ROA spectrum
12 Quantitative analysis of molecular surface
13 Process grid data (No grid data is presented currently)
14 Adaptive natural density partitioning (AdNDP) analysis
15 Fuzzy atomic space analysis
16 Charge decomposition analysis (CDA) and extended CDA (ECDA)
17 Basin analysis
18 Electron excitation analysis
19 Orbital localization analysis
20 Visual study of weak interaction
21 Energy decomposition analysis
100 Other functions (Part 1)        200 Other functions (Part 2)

本帖最后由 heyoug 于 2019-11-19 15:17 编辑

@echo off&&setlocal enabledelayedexpansion
for /f %%i in ('dir /b *.txt') do (
set BL=0
call :A %%i
)
exit
:A
for /f "tokens=1 delims=." %%i in ("%1") do echo %%i>>整理结果.txt
for /f "skip=85 tokens=*" %%i in (%1) do (
echo %%i>>整理结果.txt
set /A BL+=1
if !BL! equ 3 goto :eof
)
goto :eof

TOP

  1. @echo off
  2. pushd "%~dp0"
  3. Powershell -NoProfile -Command "Get-Item -Path .\*.txt | ForEach-Object { if ([System.IO.File]::ReadAllText($_.FullName, [System.Text.Encoding]::Default) -match 'Note:(?:.*\n){2}.*') { $_.BaseName; $Matches[0]; ''; } } | Set-Content -Path .\汇总.txt -Encoding oem "
  4. popd
  5. pause
  6. exit /b
复制代码
微信:flashercs
QQ:49908356

TOP

  1. @echo off
  2. rem setlocal enabledelayedexpansion
  3. set info=互助互利,支付宝扫码头像,感谢打赏
  4. rem 有问题,可加QQ956535081及时沟通
  5. title %info%
  6. cd /d "%~dp0"
  7. set "outfile=all.log"
  8. (for /f "tokens=1,2* delims=:" %%a in ('findstr /n "Note:" *.txt') do (
  9.     call :loop "%%a" "%%b"
  10. ))>"%outfile%"
  11. :end
  12. echo;%info%
  13. pause
  14. exit
  15. :loop
  16. set /a "n=%2-1,m=0"
  17. echo;%~n1
  18. for /f "skip=%n% delims=" %%b in ('type "%~1"') do (
  19.     echo;%%b
  20.     set /a m+=1
  21.     >nul 2>&1 set /a "1/(m-3)"||(goto break)
  22. )
  23. :break
  24. echo;
  25. exit/b
复制代码
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

  1. Select-String *.txt -Pattern '^Note:.*' -Enc Default -Context 2 | %{ $_.FileName, $_.Matches[0].Value, $_.Context.PostContext }
复制代码

TOP

返回列表