标题: [文本处理] (已解决)文本重新排列批处理求助 [打印本页]
作者: cgwang1023 时间: 2015-4-18 07:27 标题: (已解决)文本重新排列批处理求助
将下面两列数据按照后面的距离和高差形式重新排列,输出到新的文本
距离,高程值
10 备注:10为里程
-18.867 2516.487
-10.16 2516.219
0 2516.174
43.032 2517.48
46.68 2526.07 10 2516.174
50.696 2525.89 2 -10.16 -0.045 -18.867 -0.313
距离,高程值 3 43.032 -1.306 46.68 -9.896 50.696 -9.716
20 备注:20为里程 20 2525.637
-50.875 2519.381 4 -14.738 2.351 -27.493 4.919 -43.122 7.167 -50.875 6.256
-43.122 2518.47 2 6.611 0.761 18.722 -2.832
-27.493 2520.718 32 2542.025
-14.738 2523.286 5 -2.082 -0.249 -18.985 2.593 -28.116 5.449 -38.011 2.426 -50.942 -1.577
0 2525.637 4 4.69 1.891 34.109 -0.242 41.132 0.335 50.802 -0.185
6.611 2524.876
18.722 2528.469
距离,高程值
32 备注:32为里程 格式备注:
-50.942 2543.602 里程 0值后单元格高程
-38.011 2539.599 负距离数和 距离 与0值距离的高差 距离 与0值距离的高差
-28.116 2536.576 正距离数和 距离 与0值距离的高差 距离 与0值距离的高差
-18.985 2539.432
-2.082 2542.274
0 2542.025
4.69 2540.134
34.109 2542.267
41.132 2541.69
50.802 2542.21
作者: pcl_test 时间: 2015-4-18 12:57
本帖最后由 pcl_test 于 2015-4-19 23:17 编辑
- @echo off
- setlocal enabledelayedexpansion
- set "folder=处理结果"
- md "%folder%\" 2>nul
-
- for /f "delims=" %%a in ('dir /b *.csv') do (
- set t=0
- md "%%~na_tmp\" 2>nul
-
- for /f "usebackq delims=" %%b in ("%%a") do (
- set "str=%%b"
- if "!str:~,2!" equ "距离" (
- set/a t+=1
- ) else (
- >>"%%~na_tmp\%%~na_!t!.txt" echo,%%b
- )
- )
-
- pushd "%%~na_tmp\"
- (for /f "delims=" %%c in ('dir /b *.txt') do (
- ::取里程值
- for /f "tokens=1,2 delims=," %%d in ('type "%%c" ^|findstr ",,"') do set "a=%%d"
-
- ::取0距离的高程值
- for /f "usebackq tokens=1,2 delims=," %%e in ("%%c") do if "%%e" equ "0" (set "b=%%f")
- echo,!a!,!b!
- if "!b:~-3,1!" equ "." (set "b=!b!0")
- set "b=!b:.=!"
-
- ::处理负距离数据
- set sa=
- set n=0
- for /f "tokens=1,2 delims=," %%g in ('type "%%c" ^|sort /+20 ^|findstr "\-"') do (
- set "fjl=%%g"
- set /a n+=1
- set "c=%%h"
- if "!c:~-3,1!" equ "." (set c=!c!0)
- set "c=!c:.=!"
- set /a d=b-c
- if "!d:-=!" equ "!d!" (
- if "!d:~3,1!" equ "" (
- set "d=00000!d!"
- set "d=!d:~-4!
- )
- set "d=!d:~,-3!.!d:~-3!"
- ) else (
- set "d=!d:-=!"
- if "!d:~3,1!" equ "" (
- set "d=00000!d!"
- set "d=!d:~-4!
- )
- set "d=-!d:~,-3!.!d:~-3!"
- )
- set "sa=!sa!!fjl:~1!,!d!,"
- )
- echo,!n!,!sa!
-
- ::处理正距离数据
- set sb=
- set m=0
- for /f "skip=2 tokens=1,2 delims=," %%i in ('type "%%c" ^|findstr /v "\-"') do (
- set /a m+=1
- set "e=%%j"
- if "!e:~-3,1!" equ "." (set e=!e!0)
- set "e=!e:.=!"
- set /a f=b-e
-
- if "!f:-=!" equ "!f!" (
- if "!f:~3,1!" equ "" (
- set "f=00000!f!"
- set "f=!f:~-4!
- )
- set "f=!f:~,-3!.!f:~-3!"
- ) else (
- set "f=!f:-=!"
- if "!f:~3,1!" equ "" (
- set "f=00000!f!"
- set "f=!f:~-4!
- )
- set "f=-!f:~,-3!.!f:~-3!"
- )
- set "sb=!sb!%%i,!f!,"
- )
- echo,!m!,!sb!
-
- ))>"%~dp0%folder%\%%~na.csv"
-
- popd
- rd "%%~na_tmp\" /s /q
- )
-
- pause
复制代码
作者: xxpinqz 时间: 2015-4-19 11:30
楼上的厉害,个人表示完全看不懂楼主的表述。
作者: cgwang1023 时间: 2015-4-19 19:46
这是要转换横断面的数据,就是距离和高程,需要把负值的距离高程放到一行,正直的距离高程放到一行,同时统计出来正负距离和高程的个数。麻烦再问问pcl_test大侠,如果负值的距离要取正,怎么处理呢,谢谢大侠了。
作者: pcl_test 时间: 2015-4-19 20:54
回复 4# cgwang1023
取正的意思是指取绝对值吗?只是负距离值取正?与0值距离的高差需要取正吗?
作者: pcl_test 时间: 2015-4-19 23:21
回复 4# cgwang1023
已在2楼修改
作者: pcl_test 时间: 2015-4-19 23:22
问题得到解决后请在标题最前面注明[已解决]
http://www.bathome.net/thread-3473-1-1.htm
作者: cgwang1023 时间: 2015-4-20 08:35
只是负值的距离取正,高差不用取正
作者: cgwang1023 时间: 2015-4-20 08:42
谢谢大侠,可能是我表述不清,不过,你修改后的就是只是距离去绝对值的,正是我需要的,谢谢了
作者: cgwang1023 时间: 2015-4-21 21:20
@echo off
setlocal enabledelayedexpansion
set "folder=处理结果"
md "%folder%\" 2>nul
for /f "delims=" %%a in ('dir /b *.csv') do (
set t=0
md "%%~na_tmp\" 2>nul
for /f "usebackq delims=" %%b in ("%%a") do (
set "str=%%b"
if "!str:~,2!" equ "距离" (
set/a t+=1
) else (
>>"%%~na_tmp\%%~na_!t!.txt" echo,%%b
)
)
pushd "%%~na_tmp\"
(for /f "delims=" %%c in ('dir /b *.txt') do (
::取里程值
for /f "tokens=1,2 delims=," %%d in ('type "%%c" ^|findstr ",,"') do set "a=%%d"
::取0距离的高程值
for /f "usebackq tokens=1,2 delims=," %%e in ("%%c") do if "%%e" equ "0" (set "b=%%f")
echo,!a!
if "!b:~-3,1!" equ "." (set "b=!b!0")
set "b=!b:.=!"
::处理负距离数据
set sa=
set n=0
for /f "tokens=1,2 delims=," %%g in ('type "%%c" ^|sort /+20 ^|findstr "\-"') do (
set "fjl=%%g"
set /a n+=1
set "c=%%h"
if "!c:~-3,1!" equ "." (set c=!c!0)
set "c=!c:.=!"
set /a d=b-c
if "!d:-=!" equ "!d!" (
if "!d:~3,1!" equ "" (
set "d=00000!d!"
set "d=!d:~-4!
)
set "d=!d:~,-3!.!d:~-3!"
) else (
set "d=!d:-=!"
if "!d:~3,1!" equ "" (
set "d=00000!d!"
set "d=!d:~-4!
)
set "d=-!d:~,-3!.!d:~-3!"
)
set "sa=!sa!!fjl:~1!,!d!,"
)
echo,!n!,!sa!
::处理正距离数据
set sb=
set m=0
for /f "skip=2 tokens=1,2 delims=," %%i in ('type "%%c" ^|findstr /v "\-"') do (
set /a m+=1
set "e=%%j"
if "!e:~-3,1!" equ "." (set e=!e!0)
set "e=!e:.=!"
set /a f=b-e
if "!f:-=!" equ "!f!" (
if "!f:~3,1!" equ "" (
set "f=00000!f!"
set "f=!f:~-4!
)
set "f=!f:~,-3!.!f:~-3!"
) else (
set "f=!f:-=!"
if "!f:~3,1!" equ "" (
set "f=00000!f!"
set "f=!f:~-4!
)
set "f=-!f:~,-3!.!f:~-3!"
)
set "sb=!sb!%%i,!f!,"
)
echo,!m!,!sb!
))>"%~dp0%folder%\%%~na.csv"
popd
rd "%%~na_tmp\" /s /q
)
pause
我怎么按照你说的删了后,提取出来怎么里程也没有了,是不是我多删什么了
作者: pcl_test 时间: 2015-4-21 23:21
回复 10# cgwang1023
测试没有问题,是否你的csv文件格式有所改变
作者: cgwang1023 时间: 2015-4-22 12:11
回复 11# pcl_test
csv里面应该只有a、b两列,如果测试里的csv把备注那列删掉就提不出来里程了,为什么
作者: pcl_test 时间: 2015-4-22 12:56
回复 12# cgwang1023
把原文件上传,没用的文字和数字统统去掉
作者: cgwang1023 时间: 2015-4-22 16:05
回复 13# pcl_test
已经上传,这是原文件,只有这两列数据。
作者: pcl_test 时间: 2015-4-22 16:33
回复 14# cgwang1023
已修改
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |