バッチを使用してテキスト ファイルからテキストまたはシーケンスを取得しますか?

バッチを使用してテキスト ファイルからテキストまたはシーケンスを取得しますか?

というファイルがありfile.txt、その中には、

American 9876543 [email protected]
Australian 7674840 [email protected]
Indian 9364906 [email protected]
Chinese 6383936 [email protected]
Japanese 9363839 [email protected]

ここで、このファイルから 3 つの項目をフィルターして、別のテキスト ファイルに出力します。

例えば、

出力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

このファイルから3つの項目をフィルタリングして別のテキストファイルに出力したい

これを行う必要fcはありません。簡単なコマンドで十分です。findstrfor /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

参考文献

関連情報