1

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

jeb
  • 78,592
  • 17
  • 171
  • 225
Double Quotes
  • 125
  • 1
  • 2
  • 11

1 Answers1

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
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • I do apologize about my not more detailed text version, my text version with the "Copy and help..." has also a colon (:) in the line aswell. So i tried to use /c:"Copy ^"" but this doesn't work. To let the findstr know to search a line containing Copy " – Double Quotes Oct 09 '13 at 14:11
  • After some tries i got it worked with your suggestion find /i "copy " <%source% |find "\" >op.txt and also worked with find ":\" op.txt – Double Quotes Oct 09 '13 at 16:28
  • Is it ok to use find /i "copy " <%source% |find "\" >op.txt ? – Double Quotes Oct 09 '13 at 16:30
  • That's good. Yes you can search either string first and your syntax looks ok. Enclose `%source%` in double quotes if you use long filenames or pathnames or `&` in the name. – foxidrive Oct 09 '13 at 16:39
  • SET source="details.txt" , will update my main post to let you see my updated code. And foxidrive, thank you for helping me i really appriciate your help here. *sorry my English isn't that good like my coding*. – Double Quotes Oct 09 '13 at 16:47
  • Thanks. If you want to accept the answer then click the grey tick next to it. It lets others know in the future that an answer is worth trying, and it gives you, and me, extra Stack Overflow reputation. – foxidrive Oct 09 '13 at 16:54
  • But there is still a little tweak to do i try to post the updated code but can't post in into the code box. (what a fail i am) – Double Quotes Oct 09 '13 at 17:30
  • StackOverflow works on a policy of a question and a related answer. If your question changes then please open a new question, with the changed title and information. – foxidrive Oct 09 '13 at 17:38