Page 1 of 1

Writing Output

Posted: 15 Feb 2014 14:13
by booga73
I need some help please to get info from a text that is vertically placed to output horizontally into another text file; trying to produce a report of multiple stations which show no bit locker encryption.


Vertically placed sample of my text file, myTxt.txt:

    465.47 GB
    Windows 7
    Fully Encrypted
    100%
    AES 128 with Diffuser
    Protection On
    Unlocked
    None

    * =
    * =

for illustration, I would like: (delimented by a tab since my report will be in text file for later "manipulation")

465.47 GB Windows 7 Fully Encrypted 100% AES 128 with Diffuser Protection On Unlocked None



the output of the report file, bitLocker.txt, shows only:

465.47 GB

the space that is leading after 465.47 GB in my file,bitLocker.txt, has 8 tab positions. some how the remaining info isn't being written and I'll accept a simple reason why too :o

I don't really need any of the info after "None" in the myTxt.txt file either.

my code which I believe is causing the problem of writing vertically into bitLocker.txt report:

Code: Select all

for /f "tokens=1-9" %%a in (C:\Users\%username%\Documents\MyScripts\tmp\myTxt.txt) do (
set "atrib1=%%a"
set "atrib2=%%b"
set "atrib3=%%c"
set "atrib4=%%d"
set "atrib5=%%e"
set "atrib6=%%f"
set "atrib7=%%g"
set "atrib8=%%h"
set "atrib9=%%i"
goto Nxt2
)

:Nxt2
set "CPU=!atrib1!   !atrib2!   !atrib3!   !atrib4!   !atrib5!   !atrib6!   !atrib7!   !atrib8!   !atrib9!"
set cpu1=!CPU!

echo %CPU1% >> C:\Users\%username%\Documents\MyScripts\bitLocker.txt


looking for insight on how to write vertically, i'm horizontally challenged ! :shock: thank you! v/r Booga73

Re: Writing Output

Posted: 15 Feb 2014 14:49
by foxidrive
I know this will not suit you, but I love simple, robust solutions.

This works with your sample as far as I can tell.

Code: Select all

type mytext.txt |findstr "^[a-zA-Z0-9]"|repl "\r\n" "\t" xm

Re: Writing Output

Posted: 15 Feb 2014 15:09
by booga73
Hello Foxidrive


received error at dos prompt:

'repl' is not recognized as an internal or external command,
operable program or batch file.

that's when I was in the same directory as my needed text, mytext.txt.

Presently running on Win7 x64 workstation.

Re: Writing Output

Posted: 15 Feb 2014 15:16
by foxidrive
It seems like you've skipped a lot of posts in this forum, booga! :)

repl.bat was written by Dave Benham and it's a wonderful tool to have in your path, as is findrepl.bat written by Aacini, also posted in this forum.

They are hybrid batch files that use built in scripting from Windows Scripting Host and allow much of the regular expression syntax that Microsoft supplies.

findrepl has similarities to grep
repl has similarities to sed

Re: Writing Output

Posted: 15 Feb 2014 15:32
by booga73
Well, yes, I don't dive into all the discussions; I definitely didn't cover repl.bat & findrepl.bat.

but my question though, other than using repl.bat in my path to do the 1 liner code you wrote,

How would the correction to what I posted be written, as if there wasn't repl.bat nor findrepl.bat?

i'm looking for that info now though on repl.bat & findrepl.bat

thank you for patience with me :)

I love the scripting of batch; it's really empowering, leveraging talent to get the job done.


but if using your line of code and having repl.bat in my path,

Code: Select all

type mytext.txt |findstr "^[a-zA-Z0-9]"|repl "\r\n" "\t" xm


does the line of code take what's in mytext.txt and output to 2nd text file instead of vertically but horizontally?

mytext.txt
    465.47 GB
    Windows 7
    Fully Encrypted
    100%
    AES 128 with Diffuser
    Protection On
    Unlocked
    None

    * =
    * =

need this in 2nd text file:

465.47 GB Windows 7 Fully Encrypted 100% AES 128 with Diffuser Protection On Unlocked None

very respectfully, Booga73

Re: Writing Output

Posted: 15 Feb 2014 15:43
by Aacini

Code: Select all

@echo off
setlocal EnableDelayedExpansion

REM This code creates one single byte. Parameter: int
REM Teamwork of carlos, penpen, aGerman, dbenham
type nul > t.tmp
makecab /d compress=off /d reserveperdatablocksize=26 /d reserveperfoldersize=9 t.tmp 9.chr > nul
type 9.chr | ( (for /l %%N in (1,1,38) do pause)>nul & findstr "^" > temp.tmp )
>nul copy /y temp.tmp /a 9.chr /b
del t.tmp temp.tmp
for /F "delims=" %%a in (9.chr) do set "TAB=%%a"
del 9.chr

set "CPU="
for /F "delims=" %%a in (C:\Users\%username%\Documents\MyScripts\tmp\myTxt.txt) do (
   for %%b in (%%a) do (
      set "CPU=!CPU!!TAB!%%b"
      if "%%b" equ "None" goto break
   )
)
:break
echo "!CPU:~1!"


Antonio

PS - I suggest you to change the reference about "text that is vertically placed" in your description. A series of lines are not "vertically placed". The text below is:
V
e
r
t
i
c
a
l
l
y

p
l
a
c
e
d :wink:

Re: Writing Output

Posted: 15 Feb 2014 15:59
by booga73
what a whopper of code compared to Foxidrive. Realistically, I'm going to play with both, the code posted and repl.bat, i'll post my feed back.

heading out . .. Keep It Simple

v/r Booga73

Re: Writing Output

Posted: 15 Feb 2014 21:46
by foxidrive
booga73 wrote:but if using your line of code and having repl.bat in my path,

Code: Select all

type mytext.txt |findstr "^[a-zA-Z0-9]"|repl "\r\n" "\t" xm


does the line of code take what's in mytext.txt and output to 2nd text file instead of vertically but horizontally?


Yes, it does. repl here replaces the line endings with a TAB character. It assumes that the file has normal Windows CR/LF pairs.

findstr filters only the lines starting with a alpha or numeric character.

Re: Writing Output

Posted: 16 Feb 2014 11:56
by Squashman

Code: Select all

@echo off

< mytext.txt (
set /p line1=
set /p line2=
set /p line3=
set /p line4=
set /p line5=
set /p line6=
set /p line7=
set /p line8=
)

echo %line1% %line2% %line3% %line4% %line5% %line6% %line7 %line8%>bitlocker.txt

Re: Writing Output

Posted: 16 Feb 2014 18:37
by Aacini

Code: Select all

@echo off
call :JoinLines < C:\Users\%username%\Documents\MyScripts\tmp\myTxt.txt
goto :EOF

:JoinLines
set /P "line="
:nextLine
   rem Insert a TAB   v- here (instead of the spaces)
   set /P "line=%line%   "
for /F %%a in ("%line%") do if "%%a" neq "None" goto nextLine
echo %line%
exit /B


Antonio

Re: Writing Output

Posted: 16 Feb 2014 18:41
by Squashman
Aacini wrote:

Code: Select all

@echo off
call :JoinLines < C:\Users\%username%\Documents\MyScripts\tmp\myTxt.txt
goto :EOF

:JoinLines
set /P "line="
:nextLine
   rem Insert a TAB   v- here (instead of the spaces)
   set /P "line=%line%   "
for /F %%a in ("%line%") do if "%%a" neq "None" goto nextLine
echo %line%
exit /B


Antonio


I like it! :D