If findstr first charatcter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Costy
Posts: 4
Joined: 25 Feb 2018 10:43

If findstr first charatcter

#1 Post by Costy » 07 Mar 2018 12:41

Hi everyone I have this code:

-----------------------------------------------------
$ linetoselect sasa
asdlaldsalda
ld
als
alds
lda
lds
l
linetoselect sasa
akdskadkskdsadk
askdskdak
ksadkakd
adkpskdak
aksds
$ linetoselect
sdsad
sda
sdad
adsa


linetoselect ssa
sda
kksk
kkk
awda
-----------------------------------------------------

I would write a batch code doing the following step
If the first character of (Findstr /n /c: linetoselect ) = "$" else >> file.txt

At the end of the code I would have a file.txt where only linetoselect not starting with $ are reported


Could anyone help me?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: If findstr first charatcter

#2 Post by ShadowThief » 07 Mar 2018 13:15

As long as linetoselect lines won't contain $ anywhere other than the start of the line, you can search for linetoselect and then pipe that to a second findstr that finds lines that don't contain $

Code: Select all

findstr /n /c:"linetoselect" raw_data.txt | findstr /v /c:"$" >>file.txt
Note that I've assumed the data is in a file called raw_data.txt.

Costy
Posts: 4
Joined: 25 Feb 2018 10:43

Re: If findstr first charatcter

#3 Post by Costy » 07 Mar 2018 14:07

Thanks a lot for your help it works and in order to consider only $ at the beginning of the line it needs add /b.
Thanks a lot. Best regards

Post Reply