1

I have a text file that has fixed length data.

1234|test1|2015|Who are you
4567|test2||I'm a dumb guy
1234|test1|2015|We all know

I just need to remove line 2 by checking if position 12th value <> 2 (current year so will always be 2 for all rows until 2099 :)) then remove that line. In other words, just fetch rows which contains value 2 in position 12.

I tried searching and found this but I dont know how to re-write to look for a position = value.

type file.txt | findstr /v ERROR | findstr /v REFERENCE

Delete certain lines in a txt file via a batch file

Thanks so much..

1 Answer 1

3
findstr /r "...........2" "Data.txt"

See findstr /? for help. Also help.

Redirect output to a file.

findstr /r "...........2" "c:\folder\Data.txt" > "c:\folder\Output.txt"

See Trouble with renaming folders and sub folders using Batch for punctuation help.

2
  • Wouldn't it be /v /r? Feb 20, 2016 at 4:24
  • 1
    He wants to keep 2nnn not lose 2nnn. This is better ^...........2[0-9][0-9][0-9]
    – user5721973
    Feb 20, 2016 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.