标题: [文本处理] 数据在txt或者是cvs文件中,如何用批处理变成四个一行排列? [打印本页]
作者: yifanwuyou 时间: 2014-12-17 21:49 标题: 数据在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
为什么没有上传文件的地方,还是我没有权限啊。
作者: DAIC 时间: 2014-12-18 10:38
- @echo off
- set "MergeRows=4"
- (for /f %%a in (a.txt) do (
- set /a n+=1
- set /a m=n%%%MergeRows%
- set /p=%%a <nul
- set /a test=1/m 2>nul || echo;
- ))>b.txt
复制代码
作者: yiwuyun 时间: 2014-12-18 16:13
有意思,用0作除数作为判断换行的条件
作者: yifanwuyou 时间: 2014-12-18 21:24
回复 2# DAIC
非常感谢,查了好多资料才明白基本的意思了,但是有一点不明白,为什么for语句前面要有括号呢,没括号执行起来就不对。
还有一个就是,可以帮忙看下我这个怎么简化一下吗?因为我只会用一条一条输出,就像下面用了4个>>thermalchemical.txt ,可以简化成一个吗,像你上面弄的那样。找完了再输出。- @echo off
- echo.
- echo 命令正在执行......
- set /a sum=0
- for /l %%n in (1,1,50) do (
- if exist %%n.log (
- find "Sum of electronic and zero-point Energies" %%n.log >>thermalchemistry.txt
- find "Sum of electronic and thermal Energies" %%n.log >>thermalchemistry.txt
- find "Sum of electronic and thermal Enthalpies" %%n.log >>thermalchemistry.txt
- find "Sum of electronic and thermal Free Energies" %%n.log >>thermalchemistry.txt
- set /a sum=sum+1
- )
- )
复制代码
作者: DAIC 时间: 2014-12-19 10:54
回复 4# yifanwuyou
为什么for语句前面要有括号呢,没括号执行起来就不对。
因为要把整个for命令作为一个整体进行重定向- @echo off
- echo 命令正在执行......
- set sum=0
- (for /l %%n in (1,1,50) do (
- if exist %%n.log (
- find "Sum of electronic and zero-point Energies" %%n.log
- find "Sum of electronic and thermal Energies" %%n.log
- find "Sum of electronic and thermal Enthalpies" %%n.log
- find "Sum of electronic and thermal Free Energies" %%n.log
- set /a sum+=1
- )
- ))>thermalchemistry.txt
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |