|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『楼 主』:
批处理实现输出退行(第二篇)
使用 LLM 解释/回答一下
怎么写这个文件?
它的目的是,在同一行输出,不另起一行
比如:
echo a >t.txt
那么在t.txt中就有了一行显示了 a
现在问题来了,
echo b >t.txt
b在文件t.txt 中另起了一行,那么怎么做才能让它紧跟着 a 前显示即:
ba
这篇文章与我上次发的有不同哦。
第一篇为:http://www.cn-dos.net/forum/viewthread.php?tid=25963&fpage=1
我想了很久也没有想到,请帮忙!!谢了
Last edited by scriptor on 2006-12-28 at 02:51 AM ]
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 ]
|
|
2006-12-28 15:50 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
set /p =a<nul>a.txt
set /p =b<nul>>a.txt
set /p =a<nul>a.txt
set /p =b<nul>>a.txt
|
|
2006-12-28 21:13 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
NaturalJ0兄
楼主是想要先输入a,再输入b,但b在a前。
NaturalJ0 brother
The owner wants to enter a first, then enter b, but b is before a.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-28 21:34 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
反响操作就可以了
set /p =b<nul>a.txt
set /p =a<nul>>a.txt
Just perform the reaction operation.
set /p =b<nul>a.txt
set /p =a<nul>>a.txt
|
|
2006-12-28 21:42 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不知道能不能把a.txt读到变量,这样可以先把a写入之后读到变量,之后重新写入b.在写入变量就可以了,可是我不会,只能说一下自己的思路.
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.
|
|
2006-12-28 21:55 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Type 不带换行符的文件--假定内容为B 另一个文件--假定内容为A >demo.txt
(“连续” Type 命令读两个文件,按顺序将它们“连成一体”定向写入到另一个文件。)
(不带换行符内容的文件,由 set/p 建立)
那么 demo.txt 内容就会为 "BA"
要不就 copy /b ....或是 For ...
或是 “反---瞎起的名字” 定向操作……
run.bat 内容如下:
:: 假定内容为 a 的一个名为 t.txt 的文件文件已经建立。
:: 假定要将一个字符 “b” “插入” 以 t.txt 文件第1个字符的“前”面(左边),则:
@echo off
set /p var=
>t.txt Echo b%var%
另类使用上面建的代码方法:
C:\TEMP\str\k>type t.txt
a
C:\TEMP\str\k>run.bat<t.txt
C:\TEMP\str\k>type t.txt
ba
Last edited by redtek on 2006-12-28 at 09:55 AM ]
Type the file without line breaks -- assume the content is B, another file -- assume the content is A >demo.txt
(“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:
:: Assume there is a file t.txt with content a that has been created.
:: Assume to "insert" a character "b" "in front" (left) of the first character of the t.txt file, then:
@echo off
set /p var=
>t.txt Echo b%var%
Alternative use of the above built code method:
C:\TEMP\str\k>type t.txt
a
C:\TEMP\str\k>run.bat<t.txt
C:\TEMP\str\k>type t.txt
ba
Last edited by redtek on 2006-12-28 at 09:55 AM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-28 22:49 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by HUNRYBECKY at 2006-12-28 08:42:
反响操作就可以了
set /p =b<nul>a.txt
set /p =a<nul>>a.txt
不能反向输入啊,我的本意是先输入a,然后输入b的时候,
使得b放在a的前面。如果你先输入b就没有我的含义了。
Originally posted by HUNRYBECKY at 2006-12-28 08:42:
Just operate the feedback.
set /p =b<nul>a.txt
set /p =a<nul>>a.txt
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.
|
|
2006-12-28 22:59 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
看来这个难以实现??
是吗?
有人回答吗?
It seems this is difficult to achieve??
Is that so?
Is there anyone to answer?
|
|
2006-12-28 23:19 |
|
|
PPdos
高级用户
   
积分 783
发帖 268
注册 2006-12-26
状态 离线
|
『第 9 楼』:
很多人也想到了吧?
使用 LLM 解释/回答一下
@echo off
:x
set /p b=输入的字符:
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 ]
@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 ]
|
|
2006-12-29 00:12 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
一个变通的方法:
假设文件a.txt中已经有"cn-dos"字符了,要在在前面加上"www",可以在命令行这样操作:
copy /y /b con + a.txt b.txt
::输入你要加的内容之后按F6回车即可,然后将b.txt覆盖a.txt。
copy /y b.txt a.txt
::可以达到目的了,可能这不是楼主的本意。
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:
copy /y /b con + a.txt b.txt
::After entering the content you want to add, press F6 and then Enter. Then overwrite a.txt with b.txt.
copy /y b.txt a.txt
::This can achieve the purpose. Maybe this is not what the original poster intended.
|
|
2006-12-29 00:23 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
= =b 不好意思,看错楼主意思了。
echo a>t.txt
set /p tempvariable=<t.txt
echo b%tempvariable%>t.txt
如果你只有一行的话,可以这样。
= =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.
|
|
2006-12-29 00:39 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
|
2006-12-29 00:58 |
|
|
rochan
初级用户
 
积分 40
发帖 14
注册 2006-12-27
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
9楼代码有点误差..依次输入 1 2 3 4 5 6 7 8 后 k.txt文件中 会出现 8642打开 ECHO。...而不是 87654321
我改了一下..测试过了.成功!!
代码如下:
@echo off
if not exist k.txt echo. >k.txt
:x
set /p a=<k.txt
set /p b=输入的字符:
:::echo %b% >>k.txt
echo %b%%a% >k.txt
goto x
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:
@echo off
if not exist k.txt echo. >k.txt
:x
set /p a=<k.txt
set /p b=Input character:
:::echo %b% >>k.txt
echo %b%%a% >k.txt
goto x
此帖被 +2 点积分 点击查看详情 评分人:【 PPdos 】 | 分数: +2 | 时间:2006-12-29 03:10 |
|
|
|
2006-12-29 01:55 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
这倒让我想起那个输出倒文的批处理了。^_^
This reminds me of that batch script that outputs reversed text. ^_^
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-29 02:12 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
如果单是实现这样的,下面用sed的实现:
>t.txt (echo a)
set "var=b"
sed "1i\%var%" t.txt|sed "$!N;s/\n//"|more>t1.txt
type t1.txt
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
|
|
2006-12-29 02:41 |
|