The lpr man page states:
-hheader Specify a title to be used on the banner page (if any).
Default title is the name of the file.
And nothing else concerning this (meaning, as it states: "Default title is the name of the file", as you didn't pass the -h
parameter). So it looks like a misbehaviour, at least at first sight. On a second look, I notice your -p
parameter:
-p Add pr(1) style headers to each page (text only)
Taking a look at the pr(1) man page:
use a centered HEADER instead of filename in page header, -h ""
prints a blank line, don't use -h""
My guess would be that this "centered header" is only calculated once, instead for each file separately. So you could try your both approaches without the -p
parameter to check whether that introduces the problem -- or try a third approach:
for myfile in file*.txt; do lpr -p $myfile; done
which would invoke lpr
for each file separately, and thus get you rid of the described problem.
The following works well from the command line for most circumstanses
(for %F in (test1.txt test2.txt) do @more +1 "%%F") >test3.txt
Double up the percents if you use the command within a batch script.
The above has the following limitations
- Each source file must have fewer than 64k lines, else it will hang.
- Any tab characters will be converted into a string of spaces
- I think there is at least one other restriction, but my memory fails me (perhaps null bytes converted to new line??)
The following batch script has no limitation other than each line must be less than 8k in length. But it is probably too slow for large files (batch is a lousy tool for text processing):
@echo off
setlocal disableDelayedExpansion
>test3.txt (
for %%F in (test1.txt test2.txt) do for /f "skip=1 delims=" %%A in (
'findstr /n "^" "%%F"'
) do (
set "ln=%%A"
setlocal enableDelayedExpansion
echo(!ln:*:=!
endlocal
)
)
You could write a custom JScript or VB script that could do this efficiently.
My JREPL.BAT hybrid JScript/batch utility can handle this well. It is overkill, but it will efficiently do the job, even with very large files.
JREPL.BAT is a general purpose regular expression text processor, with many options. It is pure script that runs natively on any Windows machine from XP onward.
The following will work on the command line.
>test3.txt (for %F in (test1.txt test2.txt) do @JREPL "^.*" "ln>1?$0:false" /jmatch /f "%F")
If used within a batch script, then you must use CALL JREPL, and double the percents:
@echo off
>test3.txt (for %%F in (test1.txt test2.txt) do call JREPL "^.*" "ln>1?$0:false" /jmatch /f "%%F")
Best Answer
Concatenate Multiple files into One File Create Test Files
Verify test file creation
Concatenate files
Verify concatenated file creation
Verify correct contents of concatenated files