나는 다음을 포함하는 파일을 가지고 있습니다 file.txt
.
American 9876543 [email protected]
Australian 7674840 [email protected]
Indian 9364906 [email protected]
Chinese 6383936 [email protected]
Japanese 9363839 [email protected]
이제 이 파일의 세 가지 항목을 다른 텍스트 파일의 출력으로 필터링하고 싶습니다.
예를 들어,
출력 file1.txt
- 모든 메일 ID를 포함해야 합니다.
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
출력 file2.txt
- 모든 숫자를 포함해야 함
9876543
7674840
9364906
6383936
9363839
출력 file3.txt
- A에서 시작하는 시퀀스 단어만 포함해야 합니다.
예를 들어,
American
Australian
이를 위해 FC 명령과 Findstr 명령을 사용해 보았습니다. 그리고 해당 명령을 올바르게 사용하는 방법을 모르겠습니다.
도와주세요.. 미리 감사드립니다..
답변1
이 파일의 세 가지 항목을 다른 텍스트 파일의 출력으로 필터링하고 싶습니다.
fc
당신은 이것을 할 필요 도 없고 findstr
할 필요도 없습니다. 간단한 for /f
명령이면 충분합니다.
다음 배치 파일(test.cmd)을 사용합니다.
@echo off
setlocal enabledelayedexpansion
for /f "usebackq tokens=1-3" %%a in (`type file.txt`) do (
echo %%a >> file3.txt
echo %%b >> file2.txt
echo %%c >> file1.txt
)
endlocal
사용 예:
> type file.txt
American 9876543 [email protected]
Australian 7674840 [email protected]
Indian 9364906 [email protected]
Chinese 6383936 [email protected]
Japanese 9363839 [email protected]
> test
> type file1.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
> type file2.txt
9876543
7674840
9364906
6383936
9363839
> type file3.txt
American
Australian
Indian
Chinese
Japanese
추가 자료
- Windows CMD 명령줄의 AZ 인덱스
- 분류된 Windows CMD 명령 목록
- /f에 대해- 다른 명령의 결과에 대해 명령을 반복합니다.
- 리디렉션- 리디렉션 연산자.
- 유형- 하나 이상의 텍스트 파일의 내용을 표시합니다.