问题
My sample text file is the following:
1. -77.41936 37.238461
2. -77.41932 37.238466
3. -77.419275 37.238454
4. -77.419247 37.23843
5. -77.419235 37.2384
6. -77.419243 37.238363
7. -77.419268 37.238337
8. -77.419292 37.238326
9. #N/A #N/A
10. #N/A #N/A
11. #N/A #N/A
12. #N/A #N/A
13. #N/A #N/A
14. #N/A #N/A
15. #N/A #N/A
16. #N/A #N/A
17. -77.417944 37.23563
18. -77.417906 37.235634
19. -77.417869 37.235624
20. -77.417845 37.235605
21. -77.417829 37.235583
22. -77.417826 37.235552
23. -77.417841 37.235521
24. -77.417858 37.235506
25. -77.417877 37.235496
26. #N/A #N/A
27. #N/A #N/A
28. #N/A #N/A
29. #N/A #N/A
30. #N/A #N/A
31. #N/A #N/A
32. #N/A #N/A
33. #N/A #N/A
34. -77.433782 37.23745
35. -77.433175 37.237797
36. -77.433107 37.237815
37. -77.433047 37.237814
38. -77.432991 37.2378
39. -77.432933 37.237766
40. -77.432681 37.237481
41. -77.432648 37.237432
42. -77.432634 37.237378
43. -77.432638 37.237323
44. -77.432687 37.237209
45. -77.432714 37.23716
46. -77.432772 37.237083
47. -77.432844 37.237015
48. -77.432993 37.23694
49. #N/A #N/A
50. #N/A #N/A
51. #N/A #N/A
52. #N/A #N/A
53. #N/A #N/A
>>54. #N/A #N/A
I want to separate each block of numbers. These blocks are separated by random number of lines containing #N/A
#N/A
. Each block must be save into different text file named segment"blocknumber".txt
.
Is there an easy way to do this through batch file?
回答1:
@echo off
setlocal enabledelayedexpansion
set count=1
set flag=0
for /f "delims=" %%i in (t.t) do (
if "%%i" neq "#N/A #N/A" (
set flag=0
echo %%i>>file!count!.txt
) else (
if !flag!==0 set /a count+=1
set flag=1
)
)
来源:https://stackoverflow.com/questions/24588109/split-a-text-file-into-muliple-files