![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-07 11:17 |
48,040 topics / 350,125 posts / today 0 new / 48,252 members |
| DOS批处理 & 脚本技术(批处理室) » How to insert a string at the file header? |
| Printable Version 3,086 / 8 |
| Floor1 sercomm | Posted 2004-11-30 00:00 |
| 初级用户 Posts 3 Credits 109 | |
|
How to insert a string at the beginning of a file? The requirement is that the inserted string does not contain carriage return and line feed.
I found that using echo always adds carriage return and line feed. For example, echo "hello" > file, the size of file is 7 bytes, and there is an extra carriage return and line feed at the end. How to solve this problem? |
|
| Floor2 Climbing | Posted 2004-12-01 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Use Horst's QECHO third-party tool.
------------------------------------------------------------------------ QECHO Quote echo Ver 1.3 (c) 2000 Horst Schaeffer ------------------------------------------------------------------------QECHO supports output that is not possible with the normal ECHO command: + Strings in 'single' or "double" quotes marks + ASCII byte values (decimal) + Control codes with caret, like ^L (=ASCII 12) + Symbols: CR (13), LF (10), FF (12), ESC (27) + @nn - write position (extra s.below)No terminating CR/LF is output unless specified (!) thus: QECHO "something" CR LF is same as: ECHO somethingStrings may include the other type of quotes, like: 'file "%1" done' or "file '%1' done". The same type of quotes must be doubled if used within a string, for example: "file ""%1"" done".Pipes and redirections as usual. Separators (blank, comma, semicolon) allowed. If any invalid data occur, the rest of the line will be ignored (errorlevel > 0).Some examples:++ Write to a file without CR+LF QECHO "SET X="> some.bat++ Pipe multiple lines or CR's QECHO CR,"N",CR | format A: /q/u /v:"" (FORMAT, no prompts) QECHO "D100,200",CR,"Q",CR | debug PROG.COM (DUMP thru DEBUG)++ Send control codes to printer (without CR/LF) QECHO FF > LPT1 (form feed) QECHO ESC "@", ESC "l" 10 > LPT1 (reset, margin /EPSON) Extra ----- With the @-sign you can set the write position (1...) for the following data. This allows column aligned output, even if the length of the first part is variable.Example: Qecho "%varname%" @20 "more text", CR,LF >>file.extAnother feature: A string can be input to QECHO by redirection, an then be completed by writing (or overwriting) something at the specified position. Please test to find out if you can use it...---- QECHO is freeware by Horst Schaeffer - no warranties of any kind eMail: horst.schaeffer@gmx.net= 04 AUG 2002 Use Google to search for the download address. Please write a good post title. |
|
| Floor3 sercomm | Posted 2004-12-01 00:00 |
| 初级用户 Posts 3 Credits 109 | |
|
Thanks for the answer! May I ask if this function can be completed only using the original basic commands of DOS?
|
|
| Floor4 willsort | Posted 2004-12-04 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
关于sercomm:
不用第三方工具的方法也有很多,比如下面的debug方法: @echo off |
|
| Floor5 Climbing | Posted 2004-12-04 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Re regarding sort: I've always been not very familiar with dubug. What does "1a" in "e100"insert text"1a" in the above program mean? Does it mean the end of the file? If the string is very long (exceeding 16 characters), do I need to modify the number after rcx accordingly to determine the length of the string written to the file?
|
|
| Floor6 willsort | Posted 2004-12-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re Climbing: debug is a very good tool because it is included in all Microsoft operating systems, and it can be used to access hardware ports, memory system areas, and even dynamically assemble a small program. Mathematical operations and string operations can also be used with it. The 1a here is used as the end-of-text file character, mainly for copy /a to recognize, and can also be recognized by type. The reason here is to prevent the prefix string from being of an indefinite or undeterminable length. If the string is very long, the corresponding number needs to be modified. Generally, 100 is used as the length limit. Strings longer than this are no longer suitable for writing with the debug e command.
|
|
| Floor7 Climbing | Posted 2004-12-06 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Is 1a just the character entered with Ctrl+z under the DOS command line? Thanks, I now also find that debug is really useful. It seems necessary to review the knowledge of assembly language again.
|
|
| Floor8 willsort | Posted 2004-12-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re Climbing: Yes, not just 1a, all special characters from ASCII code 01 to 1a can be entered using Ctrl+A to Ctrl+Z. In the text environments of type (type con) and copy (copy con file), they are entered directly. In edit and most other DOS text editing environments, you also need to press Ctrl+P first.
|
|
| Floor9 kcdsw | Posted 2006-06-14 12:37 |
| 中级用户 Posts 179 Credits 404 | |
|
First, extract the content of the first line and set it as a variable. Then use echo to write the prefix %variable%. Then use for /f "tokens=* skip=1" %%a in (old file) do echo %%a >> new file.
cmd @ xp |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |