Solved How can I print part of a long line to the output?

August 12, 2014 at 11:06:07
Specs: Windows 7
I've successfully used 'findstr /C:"string" *.* > results.txt' to get a file, but the lines are too long. I would like to send to the results file only my string and the next 80 characters, for instance.

See More: How can I print part of a long line to the output?

Report •

#1
August 12, 2014 at 13:11:09
@echo off & setlocal enabledelayedexpansion
(for /f "tokens=1* delims=:" %%a in ('findstr /c:"search_string_here" *.*') do (
set x=%%b
echo %%a:!x:~0,80!
))>results.txt

note that lines will still wrap unless you put the filename (%%a) on a separate line from the content-sample, or shorten the sample to accomodate the possible and unknnown length of the filename.

message edited by nbrane


Report •

#2
August 25, 2014 at 09:02:12
Finally got the chance to try this out (the data analysis isn't my only function, so there are interruptions). It hangs and I don't know near enough to debug what could well be a simple syntax oversight. Any suggestions?

Thanks!


Report •

#3
August 25, 2014 at 16:32:49
✔ Best Answer
I cut-pasted my post and ran it with no problem. Did you wait long enough? try running it like this:

setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%a in ('findstr /c:"search_string_here" *.*') do (
set x=%%b
echo --------------- %%a:!x:~0,80!
pause
)
::======== end batch

running with echo on can be very confusing, so I added a marker for the output and a puase after each output.
ps: anything in "results.txt"?

message edited by nbrane


Report •
Related Solutions


Ask Question