China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 02:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch processing to achieve output backspace (Part 2) View 5,064 Replies 32
Original Poster Posted 2006-12-28 15:50 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
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 ]
Floor 2 Posted 2006-12-28 21:13 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
set /p =a<nul>a.txt
set /p =b<nul>>a.txt
Floor 3 Posted 2006-12-28 21:34 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
NaturalJ0 brother
The owner wants to enter a first, then enter b, but b is before a.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 4 Posted 2006-12-28 21:42 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Just perform the reaction operation.

set /p =b<nul>a.txt
set /p =a<nul>>a.txt
Floor 5 Posted 2006-12-28 21:55 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
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.
Floor 6 Posted 2006-12-28 22:49 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline

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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 7 Posted 2006-12-28 22:59 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
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.

Floor 8 Posted 2006-12-28 23:19 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
It seems this is difficult to achieve??

Is that so?

Is there anyone to answer?
Floor 9 Posted 2006-12-29 00:12 ·  新西兰 奥克兰大区 奥克兰 Microsoft
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
@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 ]
Floor 10 Posted 2006-12-29 00:23 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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.
Floor 11 Posted 2006-12-29 00:39 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
= =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.
Floor 12 Posted 2006-12-29 00:58 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Floor 13 Posted 2006-12-29 01:55 ·  中国 湖北 武汉 电信
初级用户
Credits 40
Posts 14
Joined 2006-12-27 11:38
19-year member
UID 74713
Gender Male
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
PPdos +2 2006-12-29 03:10
Floor 14 Posted 2006-12-29 02:12 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
This reminds me of that batch script that outputs reversed text. ^_^
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 15 Posted 2006-12-29 02:41 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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
Forum Jump: