4
I'm writing a logfile for a backup solution.
The backup solution is a simple 7-zip update command.
I'd like to log which files it backups. If I use >> log.txt I will get the result, but also lots of other information that 7-zip outputs that I don't want.
I'm looking for a way to partially log what is on the screen. I don't mind to use 7z .... >templog.txt and then doing something to templog.txt before appending it to log.txt. But I don't know how to selectively remove lines from templog.txt from the commandline either.
So I guess my question boils down: How can I remove the first 10 lines from templog.txt or alternatively only redirect part of the output on screen to a logfile?
Bonus question: How to selectively remove lines from templog.txt or the output redirection that are not at the beginning?
I looked into Findstr but given that it searches for words rather than actual strings or I have to use regexes, it seemed to not fit my needs. using SED however does. I'd love to see a proper solution that does not require any additional software though. This answer definitely deserves a +1 so that has been given. I'm going to wait a few more days to see if more answers are given before accepting this one. – LPChip – 2016-09-01T14:53:08.057
The regex one is definitely more interesting. Can it regex over the content of the entire file, past newlines too? So if I find a string, remove from there all the way until I find another string which is 8 lines down for example? – LPChip – 2016-09-01T16:20:03.327
@LPChip
– DavidPostill – 2016-09-01T16:36:14.133findstr
can search across line breaks. See http://ss64.com/nt/findstr-linebreaks.html2
@LPChip What are the undocumented features and limitations of the Windows FINDSTR command? by dbenham (our resident batch file guru) is worth a read ...
– DavidPostill – 2016-09-01T16:37:56.140Windows 8.1 or 10, and the output of the tempfile will be 20 to 30 lines big possibly, but lets say in extreme cases, the file is still under 1 mb. Well within the limits of findstr. Diving more and more into findstr, it seems I might be able to use the match against other file option to accomplish my goal the quickest. – LPChip – 2016-09-01T16:46:06.237
@LPChip I think it'll work just fine then regardless with Findstr and you just tell it what action you want it to take accordingly whether match, exclude, omit, append, etc. I think it'll work just fine with your explanation so it should be easy enough for you to test. Let me know how it goes... I did this on Windows 10 from my side today for my answers by the way. – Pimp Juice IT – 2016-09-01T16:48:48.983
Awesome. Yeah, I'll be testing this tomorrow. The target pc is those of my parents, where I implemented a simple backup solution that backups their documents to a 7z file on shutdown (gpedit) Due to it being at a moment there is no user interaction, I needed a logfile. Given that its not my pc, a logfile is always great for troubleshooting, but the 7z output is just too much, and only using the stderr is insufficient (which does show when it was unable to update the file due to it being in use, but given that I don't expect that to happen, I want to refine the logging a bit more. – LPChip – 2016-09-01T20:14:00.823
Doesn't sound like a good idea. Much work for something small. Their documents are not much. I think 2gb or something like that, but the update 7z takes less than a second for no files to backup anyway. – LPChip – 2016-09-01T22:15:25.010
@LPChip No worries, I usually remove my comments to keep it clean though; just let me know how it goes when you get to it. – Pimp Juice IT – 2016-09-02T00:14:49.967