![]() |
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-29 08:54 |
47,816 topics / 349,916 posts / today 0 new / 48,265 members |
| DOS批处理 & 脚本技术(批处理室) » Batch processing to achieve output backspace (Part 2) |
| Printable Version 5,505 / 32 |
| Floor1 scriptor | Posted 2006-12-28 15:50 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
How to write this file?
Its purpose is to output on the same line without starting a new line. For example: echo a >t.txt Then there is a line in t.txt showing a. Now the problem is, echo b >t.txt b starts a new line in file t.txt. So how to make it display immediately after a, that is: ba This article is different from my last post. The first one is: http://www.cn-dos.net/forum/viewthread.php?tid=25963&fpage=1 I have thought about it for a long time and haven't come up with it. Please help! Thanks [ Last edited by scriptor on 2006-12-28 at 02:51 AM ] |
|
| Floor2 NaturalJ0 | Posted 2006-12-28 21:13 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
set /p =a<nul>a.txt
set /p =b<nul>>a.txt |
|
| Floor3 ccwan | Posted 2006-12-28 21:34 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
NaturalJ0 brother
The owner wants to enter a first, then enter b, but b is before a. |
|
| Floor4 HUNRYBECKY | Posted 2006-12-28 21:42 |
| 银牌会员 Posts 442 Credits 1,179 | |
|
Just perform the reaction operation.
set /p =b<nul>a.txt set /p =a<nul>>a.txt |
|
| Floor5 jmz573515 | Posted 2006-12-28 21:55 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
I don't know if I can read a.txt into a variable. In this way, I can first write a into it, then read it into the variable, then rewrite b. It's okay to write into the variable, but I don't know how, so I can only talk about my own ideas.
|
|
| Floor6 redtek | Posted 2006-12-28 22:49 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
(“Continuously” type command reads two files, and sequentially “connects them together” and redirects to write to another file.) (The file with content without line breaks is created by set/p) Then the content of demo.txt will be "BA" Or copy /b .... or For ... Or “anti -- randomly named” redirect operation... The content of run.bat is as follows: Alternative use of the above built code method:
[ Last edited by redtek on 2006-12-28 at 09:55 AM ] |
|
| Floor7 scriptor | Posted 2006-12-28 22:59 |
| 银牌会员 Posts 555 Credits 1,187 | |
Originally posted by HUNRYBECKY at 2006-12-28 08:42: Can't input in reverse. My original intention is to first input "a", and then when inputting "b", make "b" come before "a". If you input "b" first, it won't have my meaning. |
|
| Floor8 scriptor | Posted 2006-12-28 23:19 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
It seems this is difficult to achieve??
Is that so? Is there anyone to answer? |
|
| Floor9 PPdos | Posted 2006-12-29 00:12 |
| 高级用户 Posts 268 Credits 783 | |
|
@echo off
:x set /p b=Input character: echo %b%>>k.txt set /p a=<k.txt&echo %b%%a%>k.txt set /p a=<k.txt&echo %b%%a%>k.txt goto x pause>nul [ Last edited by PPdos on 2006-12-28 at 11:30 AM ] |
|
| Floor10 lxmxn | Posted 2006-12-29 00:23 |
| 版主 Posts 4,938 Credits 11,386 | |
|
A workaround: Suppose the file a.txt already has the "cn-dos" character, and you want to add "www" in front of it. You can operate in the command line like this: |
|
| Floor11 NaturalJ0 | Posted 2006-12-29 00:39 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
= =b Sorry, I misread the LZ's meaning.
echo a>t.txt set /p tempvariable=<t.txt echo b%tempvariable%>t.txt If you have only one line, you can do it like this. |
|
| Floor12 scriptor | Posted 2006-12-29 00:58 |
| 银牌会员 Posts 555 Credits 1,187 | |
| Floor13 rochan | Posted 2006-12-29 01:55 |
| 初级用户 Posts 14 Credits 40 | |
|
There is a bit of error in the code on floor 9.. After inputting 1 2 3 4 5 6 7 8 in sequence, the k.txt file will have 8642 instead of 87654321.
I made some changes.. Tested it and it succeeded!! The code is as follows: |
|
| Floor14 ccwan | Posted 2006-12-29 02:12 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
This reminds me of that batch script that outputs reversed text. ^_^
|
|
| Floor15 vkill | Posted 2006-12-29 02:41 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
If it's just to implement such a thing, the following is the implementation with sed:
>t.txt (echo a) set "var=b" sed "1i\%var%" t.txt|sed "$!N;s/\n//"|more>t1.txt type t1.txt |
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |