How do you echo lines with special characters to file?

Jul 4, 2009
2
0
I grab a line from a text file to a variable and output it to another. Example: DO line IN @file1.txt echo %line >> file2.txt ENDDO It has a problem: special characters like " ` < > | and long lines (is there a variable length limit?) are not appended to the file but are printed on screen. How do make it do the job properly (like it does when the lines aren't too long and don't contain special characters)? As a workaround, I'm replacing all occurrences of special characters, like " with ---doublequote---, and then replacing them back to original when the echoing is done. If this is the only way, how would I do that for all special characters in a whole file? Got code? Now I'm doing it manually in text editor, and perhaps will record a macro for it. How do I remove the appended lines from the original file?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
textparser wrote:
| I grab a line from a text file to a variable and output it to
| another. Example: DO line IN @file1.txt echo %line >> file2.txt
| ENDDO It has a problem: special characters like " ` < > | and long
| lines (is there a variable length limit?) are not appended to the
| file but are printed on screen. How do make it do the job properly
| (like it does when the lines aren't too long and don't contain
| special characters)? As a workaround, I'm replacing all occurrences
| of special characters, like " with ---doublequote---, and then
| replacing them back to original when the echoing is done. If this
| is the only way, how would I do that for all special characters in a
| whole file? Got code? Now I'm doing it manually in text editor, and
| perhaps will record a macro for it.

That's what the new feature in V10: binary buffers were invented for. Look
at the functions @B...!
--
HTH, Steve
 
Jul 4, 2009
2
0
I'm unfamiliar with those. How would you do the equivalent of what I did, with @B...? How do you delete the lines from the original after appending them to a new file?
 
I grab a line from a text file to a variable and output it to another. Example: DO line IN @file1.txt echo %line >> file2.txt ENDDO It has a problem: special characters like " ` < > | and long lines (is there a variable length limit?) are not appended to the file but are printed on screen. How do make it do the job properly (like it does when the lines aren't too long and don't contain special characters)?

see http://mindprod.com/products.html#SAY!
includes MASM and C versions if you want to compose a short string containing control chars and special chars and redirect it to a file.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,447
88
Albuquerque, NM
prospero.unm.edu
I grab a line from a text file to a variable and output it to another. Example: DO line IN @file1.txt echo %line >> file2.txt ENDDO It has a problem: special characters like " ` < > | and long lines (is there a variable length limit?) are not appended to the file but are printed on screen. How do make it do the job properly (like it does when the lines aren't too long and don't contain special characters)? As a workaround, I'm replacing all occurrences of special characters, like " with ---doublequote---, and then replacing them back to original when the echoing is done. If this is the only way, how would I do that for all special characters in a whole file? Got code? Now I'm doing it manually in text editor, and perhaps will record a macro for it. How do I remove the appended lines from the original file?

You might also be interested in this:

http://www.unm.edu/~cdye/plugins/safechars.html
 
Similar threads
Thread starter Title Forum Replies Date
fpefpe How to? command echo in title line/bar Support 2
vefatica @EXECSTR clobbers @ECHO ON Support 2
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
D Does TCC improve CMD's implementation of ECHO? Support 6
E My echo full file name to the clipboard fails now. Support 2
MickeyF how to ECHO in opposite colors? Support 12
Joe Caverly Echo message works without the space? Support 3
T Fixed Echo randomly activated in script Support 4
S How to? ^C echo Support 6
vefatica ECHO is very slow Support 9
J How to? Riddle: How to echo > into a file? Support 7
Alexander How to? how can I use Cyrillic characters in the Echo command? Support 8
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
vefatica WAD DO, ECHO, and trailing whitespace Support 3
nickles WAD echo "%PROGRAMFILES(X86)%" Support 16
J Can you redirect output to printer device with echo? Support 1
M How to? Save and then restore "Echo" status Support 2
T Set 1% then Echo 1% Support 9
M echo %@index[1234,.,-1] return -21 in new version Support 3
Roedy ECHO bug Support 4
vefatica Continued lines (^) in a library routine? Support 5
R Lines between COMMENT & ENDCOMMENT not ignored Support 7
A TCMD - Dir Command puts out blank lines? Support 16
T FFind - can we display n number of lines after the find? Support 2
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
JohnQSmith Weird DIR output (missing lines) Support 1
fpefpe Documentation Comment lines? Support 2
nickles Fixed Executing long command lines in a batch generates file name errors Support 16
B %@lines doesn't count last line without cr/lf at eof Support 1
nikbackm How to? Find duplicate lines in text file Support 0
S Documentation HELP nit: @LINES Support 5
B Select and run lines from Command Input panel? Support 1
D WAD New envars for @LINES are not hidden Support 8
T Documentation @LINE[CON,n] @LINES[CON] not documented (bug?) Support 4
M How to? Parsing lines containing double quotes... Support 3
Stefano Piccardi echoerr truncates long lines Support 9
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
samintz How to? Pull out multiple matching lines Support 5
W Copy+Paste without breaking long lines as default? Support 1
L "for" in multiple lines Support 2
vefatica @LINES, long lines, TCC disappears Support 7
D Blank lines in jpstree.idx Support 3
T @Word from Lines with Pipes Support 3
vefatica @LINES[]? Support 1
J Extra blank lines during paste Support 6
vefatica How many lines are in this file? Support 17
nikbackm Trim last N lines from a file Support 6
B @lines: first line in the file is numbered 1 Support 0
R Reading an Unicode file with more than 8191 lines Support 1
C writing folder names with JPSoft special chars like &...... Support 4

Similar threads