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

[文本处理] 数据在txt或者是cvs文件中,如何用批处理变成四个一行排列?


-764.916697
-764.901214
-764.90027
-764.960126
-764.914554
-764.898895
-764.897951
-764.959129
变成
-764.916697        -764.901214        -764.90027        -764.960126
-764.914554        -764.898895        -764.897951        -764.959129
为什么没有上传文件的地方,还是我没有权限啊。

回复 4# yifanwuyou


为什么for语句前面要有括号呢,没括号执行起来就不对。

因为要把整个for命令作为一个整体进行重定向
  1. @echo off
  2. echo 命令正在执行......
  3. set sum=0
  4. (for /l %%n in (1,1,50) do (
  5.     if exist %%n.log (
  6.         find "Sum of electronic and zero-point Energies" %%n.log
  7.         find "Sum of electronic and thermal Energies" %%n.log
  8.         find "Sum of electronic and thermal Enthalpies" %%n.log
  9.         find "Sum of electronic and thermal Free Energies" %%n.log
  10.         set /a sum+=1
  11.     )
  12. ))>thermalchemistry.txt
复制代码

TOP

回复 2# DAIC


    非常感谢,查了好多资料才明白基本的意思了,但是有一点不明白,为什么for语句前面要有括号呢,没括号执行起来就不对。
    还有一个就是,可以帮忙看下我这个怎么简化一下吗?因为我只会用一条一条输出,就像下面用了4个>>thermalchemical.txt   ,可以简化成一个吗,像你上面弄的那样。找完了再输出。
  1. @echo off
  2. echo.
  3. echo 命令正在执行......
  4. set /a sum=0
  5. for /l %%n in (1,1,50) do (
  6. if exist %%n.log (
  7. find "Sum of electronic and zero-point Energies" %%n.log >>thermalchemistry.txt
  8. find "Sum of electronic and thermal Energies" %%n.log >>thermalchemistry.txt
  9. find "Sum of electronic and thermal Enthalpies" %%n.log >>thermalchemistry.txt
  10. find "Sum of electronic and thermal Free Energies" %%n.log >>thermalchemistry.txt
  11. set /a sum=sum+1
  12. )
  13. )
复制代码

TOP

有意思,用0作除数作为判断换行的条件

TOP

  1. @echo off
  2. set "MergeRows=4"
  3. (for /f  %%a in (a.txt) do (
  4.     set /a n+=1
  5.     set /a m=n%%%MergeRows%
  6.     set /p=%%a    <nul
  7.     set /a test=1/m 2>nul || echo;
  8. ))>b.txt
复制代码

TOP

返回列表