Extract a line with a string with double quote by using findstr

半世苍凉 提交于 2019-12-08 05:16:09

问题


First of all thank you for this site, I'm a terrible coder and so i need your help with making a batch script, i try to extract only lines that contains Copy " in that line from a text file by using findstr which actually works without that whitespace and double quote. But it will extract the line with "Copy and Help" too which i don't need.

Example:

My text contains (source.txt)

a
asd Copy and help with these command prompt:
a
  asd Copy "c:\.." a b c(white space)
a
 asd Copy and help with these command prompt:
Copy "d:\.." a c c(tab space)
avs
    Copy "e:\.." a a c
vvddf

Output file (op.txt) (should be)

Copy "c:\.." a b c
Copy "d:\.." a c c
Copy "e:\.." a a c

After my original code I tried to use

findstr /c:"Copy ^"" > op.txt
but this doesn't work. To let the findstr know to search a line containing
Copy "
Copy[whitespace][double quote]

Updated section

First off my required batch script is working from help by foxidrive. There is still some tweak to do, but i will post it as another question. This question is answered.

This is my updated code for now.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET source="details.txt"
IF EXIST %source% (
  FIND /i "copy " <%source% |FIND "\" >op.txt
) ELSE (
  Exit
)

Thanks foxidrive for the start off and solving my first issue.

Sorry for my English, it's poor like my coding


回答1:


A simplistic solution is to use this

find ":\" <source.txt  >op.txt

Or this is another workaround:

find ":\" <source.txt |find /i "copy " >op.txt


来源:https://stackoverflow.com/questions/19272357/extract-a-line-with-a-string-with-double-quote-by-using-findstr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!