找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 27924|回复: 4

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

[复制链接]
发表于 2014-12-17 21:49:50 | 显示全部楼层 |阅读模式

-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
为什么没有上传文件的地方,还是我没有权限啊。
发表于 2014-12-18 10:38:33 | 显示全部楼层
  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
复制代码
发表于 2014-12-18 16:13:34 | 显示全部楼层
有意思,用0作除数作为判断换行的条件
 楼主| 发表于 2014-12-18 21:24:54 | 显示全部楼层
回复 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. )
复制代码
发表于 2014-12-19 10:54:33 | 显示全部楼层
回复 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
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 02:55 , Processed in 0.019329 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表