-6

How can we achieve deleting lines starting with specific characters in a huge text file using a batch file?

e.g:

oldfile.txt is:

line 1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam

line 2 euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

line 3 aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor

line 4 vel illum dolore eu feugiat nulla.

deleting lines starting with "eui" and "ali";

newfile.txt becomes:

line 1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam

line 4 vel illum dolore eu feugiat nulla.

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
  • Please read the entire [tour page](http://stackoverflow.com/tour) and learn how this site works! – aschipfl Sep 19 '16 at 15:37
  • Thanks for your advice, i prefer learning through experiencing if you don't mind! – Akın Aktansel Sep 19 '16 at 15:44
  • 5
    Actually I do mind, because your post is not a real question (following the rules of this site) but a task request! Please regard that StackOverflow is not a free code writing service! So try it on your own and when stuck, come back here, share your efforts and ask a specific question! – aschipfl Sep 19 '16 at 15:47
  • i tried but i couldn't. be cool, task is not yours! – Akın Aktansel Sep 19 '16 at 16:03
  • No worries, I am cool... The thing is, questions that are not [on-topic](http://stackoverflow.com/help/on-topic) are likely volted to be closed... – aschipfl Sep 19 '16 at 16:07
  • thanks. if you havent wasted my time -and yours- and replied a simple answer, i would now be working on the topics of my profession. i am intelligent enough to be aware of here is not a free coding service. – Akın Aktansel Sep 19 '16 at 17:11
  • Funny (sarcastic), there's always something going down in the comments these days. Take a look at my edit. – Jonas Sep 19 '16 at 18:05
  • 2
    @AkınAktansel - And yet you're not intelligent enough to not post an off-topic question. [RTFM](http://stackoverflow.com/help/on-topic). – SomethingDark Sep 19 '16 at 19:25
  • @Jonas but what is the batch file exactly for removing lines starting with eui and ali, not Lorem and euismod? yes man as you guessed, this was a sarcastic joke :) thanks for your gracious support, it works perfect! – Akın Aktansel Sep 19 '16 at 20:34
  • @SomethingDark there is something dark about you, sorry to bother everyone, i am new and will be more careful next time. – Akın Aktansel Sep 19 '16 at 20:34

2 Answers2

0

Try:

@ECHO ON
findstr /v "Lorem euismod" "%USERPROFILE%\Desktop\test.txt" > "%USERPROFILE%\Desktop\outfile.txt"
PAUSE

It deletes line 1 and line 2 in test.txt. I used Lorem euismod as reference.

Check out this link.

Community
  • 1
  • 1
Jonas
  • 1,105
  • 1
  • 15
  • 21
0

To avoid deleting lines with one or more of the search terms in the middle of the string somewhere, instead of just at the beginning as requested, add the /B option to fix that:

findstr /B /V "eui ali" "input.txt" > "output.txt"