관심없는 헤더와 관련 데이터가있는 여러 텍스트 파일이 있습니다. 모든 중요한 데이터가 포함 된 새 파일을 원합니다.
예 :
File1에 텍스트가 있습니다.
Created on 02.02.2016
Country: Chile
Figure of Station: CAL
Frequency: 220 Hz
Messuring: 15 hours
File2에는 텍스트가 있습니다.
Created on 02.02.2016
Country: Chile
Figure of Station: GUA
Frequency: 220 Hz
Messuring: 14 hours
다음과 같은 모든 중요한 데이터가 포함 된 새 CSV를 갖고 싶습니다.
CAL 220 Hz 15 hours
GUA 220 Hz 14 hours
배치 파일로 이와 같은 작업을 수행 할 수 있습니까?
나는 .csv
모두 복사에 대해 알고 .txt
있지만 여기에서는 작동하지 않습니다.
여기에 내가 가진 배치 스크립트도 있습니다.
@echo off
setlocal EnableDelayedExpansion
if exist result.csv del result.csv
for %%f in (*.txt) do (
set i=0
for /F "delims=" %%l in (%%f) do (
set /A i+=1
set line!i!=%%l
)
echo %%f, !line1!, !line2!, !line3!, !line4!, !line5!, >> result.csv
)
원하는 결과를 생성하도록 배치 파일을 수정했습니다.
다음 배치 파일 (test.cmd)을 사용합니다.
@echo off
setlocal EnableDelayedExpansion
if exist result.csv del result.csv
for %%f in (file*.txt) do (
set _line=
rem we don't need the first 2 lines so skip them
rem we only need the data after the :
rem so use : as the delimeter and get the rest of the tokens after the delimeter
for /f "skip=2 tokens=2* delims=:" %%l in (%%f) do (
set _value=%%l
rem strip off the space that is after the : and build up the output line
set _line=!_line!!_value:~1!
)
rem write the output line to the file
echo !_line! >> result.csv
)
endlocal
노트:
file*.txt
텍스트 파일과 일치하도록 변경 하십시오.사용 예 :
F:\test>type file*.txt
file1.txt
Created on 02.02.2016
Country: Chile
Figure of Station: CAL
Frequency: 220 Hz
Messuring: 15 hours
file2.txt
Created on 02.02.2016
Country: Chile
Figure of Station: GUA
Frequency: 220 Hz
Messuring: 14 hours
F:\test>test
F:\test>type result.csv
CAL 220 Hz 15 hours
GUA 220 Hz 14 hours
F:\test>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다