Can formfeed character be written to file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Can formfeed character be written to file

#1 Post by Jer » 21 Oct 2015 15:35

Is it possible to have a formfeed character assigned to a variable, then use that variable
to insert page breaks by design in a text file? The next step would be to open the
text file in a word processor and the page breaks would be there. I don't know if the
formfeed in the text file would translate to a page break in the word processor.
I have Windows 7 and MS Word.

My project involves writing a formatted report from a batch file into, what I used to call
in the work world, a disjoint report. The plan is to view the report, with pauses between each
page, in a DOS window, now working, with the option to write to a text file for import into a
word processor. Columns would be aligned in Word using a fixed-width font.
Strictly a just-for-fun type or project.
Thanks.

Code: Select all

@echo Off
Type NUL>temp.txt
For /L %%n In (1 1 5) Do Echo %%n>>temp.txt
Rem add a formfeed character
::Echo %ff%>>temp.txt
For /L %%n In (6 1 10) Do Echo %%n>>temp.txt

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Can formfeed character be written to file

#2 Post by npocmaka_ » 21 Oct 2015 15:46

Code: Select all

@echo off
for /f %%# in ('cls') do set "FF=%%#"

echo "%FF%"


or


viewtopic.php?p=23888

->

Code: Select all

@echo off
setlocal

::Define a Linefeed variable
set LF=^


::above 2 blank lines are critical - do not remove.

::Create a TAB variable
call :hexprint "0x0C" FF
echo "%FF%"
exit /b

:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b


You can also use certutil, mshta , chrgen ( http://ss64.com/nt/syntax-genchr.html ) , WSH hybrid.

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can formfeed character be written to file

#3 Post by Jer » 22 Oct 2015 01:06

Thanks for the reply. I tried your method and echoed the text and formfeed character
to a text file, then opened the text file in Word and the pagebreak was there.
The two double quotes were there also; not a clean solution. I was unable to
parse %FF% to get the character without quotes, I just ended up with a blank variable.

I checked the link but decided to use a shorter solution. I copied the character to a
file named ffeed.chr, and use the TYPE command to add it to a text file.

If any on the forum have a concise way to do this with one or two lines of batch code,
that is, echo the formfeed character to a file without it being enclosed with quotes,
please post your solution to add to the skills bucket.

Code: Select all

@Echo Off

Type NUL>temp.txt
For /L %%n In (1 1 5) Do Echo data %%n>>temp.txt

Rem add a formfeed character to file
Type ffeed.chr>>temp.txt

For /L %%n In (6 1 10) Do Echo data %%n>>temp.txt
Echo  temp.txt contents:
Type temp.txt

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Can formfeed character be written to file

#4 Post by npocmaka_ » 22 Oct 2015 03:30

to print it without quotes you can use

Code: Select all

(echo(%FF%)


And appending FormFeed to a file is even sipmler:

Code: Select all

cls>>temp.txt

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Can formfeed character be written to file

#5 Post by Jer » 22 Oct 2015 09:21

Both solutions work. I'll use the one-liner: cls>>temp.txt
to place form feeds where I want them in a text file.
Thank you npocmaka_.

Sponge Belly
Posts: 223
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Can formfeed character be written to file

#6 Post by Sponge Belly » 27 Apr 2016 14:17

npocmaka wrote:

Code: Select all

cls>>temp.txt


Excellent! :)

Post Reply