I want to add specific strings at the beginning and end of each line in a text document. How to achieve this?
[ Last edited by liuwei723 on 2006-4-26 at 15:09 ]
[ Last edited by liuwei723 on 2006-4-26 at 15:09 ]
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!

Originally posted by bagpipe at 2006-4-28 11:44:
@echo off
setlocal enabledelayedexpansion
set mm=%1
set /p start=输入每行开头要添加的字符串:
set /p end=输入每行结为要添加的字符串:
for /f "tokens=1,2* delim ...
Originally posted by bagpipe at 2006-4-30 12:37:
http://www.cn-dos.net/forum/viewthread.php?tid=19331&fpage=1&highlight=%2Bbagpipe
There seem to be many introductions to commands in the forum. Take a good look yourself, mainly practice it. The above...
SFile = GetFileName()
Msg = "The replacement character format is:" & vbtab & "str1:=str2" & vblf
Msg = Msg & "Omit str2 can delete str1"
Str = inputbox(Msg,"Enter the character to insert:")
if len(Str) = 0 then Wscript.Quit
'First read the file into StrOld, then write the processed string StrNew back to the file
with CreateObject("Scripting.FileSystemObject")
set F = .OpenTextFile(SFile,1,True)
StrOld = F.ReadAll
set F = Nothing
set F = .OpenTextFile(SFile,2,True)
if len(Str) > 1 and instr(Str,":=") then
StrArray = split(Str,":=")
StrNew = Replace(StrOld,StrArray(0),StrArray(1))
else
StrNew = InertStr()
end if
F.Write(StrNew)
end with
'Insert character function, read each character in turn and judge whether it is space, carriage return, line feed
Function InertStr()
for i = 1 to len(StrOld)
if mid(StrOld,i,1) = space(1) or _
asc(mid(StrOld,i,1)) = 13 or _
asc(mid(StrOld,i,1)) = 10 then
strTmp = strTmp & mid(StrOld,i,1)
else
strTmp = strTmp & mid(StrOld,i,1) & Str
end if
next
InertStr = strTmp
End Function
'Get the name of the file to be operated
Function GetFileName()
if WScript.Arguments.Count <> 0 Then
GetFileName = Wscript.Arguments(0)
else
with CreateObject("UserAccounts.CommonDialog")
.Filter = "Text files|*.txt|All files|*.*"
.ShowOpen
GetFileName = .Filename
end with
end if
if len(trim(GetFileName)) = 0 then Wscript.Quit
End Function
Originally posted by vkill at 2006-11-4 07:21 AM:
This problem is best solved with sed, I think~ Any characters have been tested, one sentence can do it
sed "s/^/\/span>/;s/\x24/\/span>/" test.txt
Sed download: http://www.student.northpark ... Can the replaced content be written back to the original file? I tried it, but it only shows in the command line window, I don't know how to use sed, please give me some advice.