使用批次從文字檔案中提取文字或序列?

使用批次從文字檔案中提取文字或序列?

我的檔案名稱為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

我想從此文件中過濾三件事作為另一個文本文件中的輸出

你不需要fcfindstr不需要這樣做。一個簡單的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

進一步閱讀

相關內容