
我的檔案名稱為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- 根據另一個指令的結果循環指令。
- 重定向- 重定向運算子。
- 類型- 顯示一個或多個文字檔案的內容。