简体   繁体   English

批处理脚本以从文本文件中读取特定单词并写入另一个文件

[英]Batch script to read specific word from a text file and write to another file

I need some help on a batch script which has to achieve the following : 我需要批处理脚本的一些帮助,该脚本必须实现以下目的:

  1. Placed into the root structure,with # folders 放在根结构中,带有#个文件夹
  2. Open each subfolder, then read out a specific line from a text file (name of file varies). 打开每个子文件夹,然后从文本文件中读出特定的一行(文件名各不相同)。
  3. Create another text file to show "OK" or "NOT OK" based on the presence of the previously searched line. 根据先前搜索到的行,创建另一个文本文件以显示“确定”或“不正确”。

Thanks in advance to anyone who can give me a hand. 在此先感谢任何可以帮助我的人。

I guess, it would be something like this: 我猜可能是这样的:

  • It searches for *.txt files in every folder. 它在每个文件夹中搜索* .txt文件。
  • Read each file for string "This is my line" 读取每个文件中的字符串“ This is my line”
  • if found, it would write "filename.txt" is OK in D:\\FileStatus.txt 如果找到,它将在D:\\ FileStatus.txt中写入“ filename.txt”是可以的
  • if not found, it would write "filename.txt" is Not OK in D:\\FileStatus.txt 如果找不到,它将在D:\\ FileStatus.txt中写入“ filename.txt”是不正确的

@echo off @回声关闭

Set DirToSearch="D:\MyFolders\"
Set LineToRead="This is my line"

pushd %DirToSearch%
for /r %%f in (*.txt) do (
    For /F %%l in ('Findstr /L /I %LineToRead% "%%f"') do (
     if %%l equ " " (
        echo File:"%%f" is Not OK >> D:\FileStatus.txt
     ) else (
        echo Line: %%l
        echo File:"%%f" is OK >> D:\FileStatus.txt
     )
)
)

Goto :End

:End
popd

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何读取文本文件并将其逐字写入python中的另一个文件? - How to read a text file and write it word by word into another file in python? 从文本文件中读取特定单词,然后保存下一个单词 - Read a specific word from a text file and then save the next word 批处理脚本从源文件中读取文件名并将所有出现的路径写入输出文件 - Batch script to read from file name from source file and write path of all occurrences into output file 使用批处理删除文本文件中特定单词之前的文本 - Delete text before specific word in text file using batch 在批处理脚本中读取文件并从中获取值 - Read a file and obtain a value from it in batch script 从文件读取并将其写入另一个文件 - Read from file and write it to another file Python从文件读取行,然后从特定的行号写入另一个文件 - Python read lines from a file and write from a specific line number to another file 使用erlang在文本文件中特定行的末尾写一个单词 - Write a word at the end of a specific line in a text file using erlang C ++计算一个文件中单词的出现次数并写入另一个文件 - C++ count occurence of the word from a file and write to another file 读取两个文本文件并将这两个文本文件中的特定行写入第三个文件 - Read two text files and write specific lines from those two text files into a third file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM