當前位置:首頁 » 編程軟體 » 腳本讀取文本

腳本讀取文本

發布時間: 2022-06-18 20:09:09

1. 批處理腳本循環讀取txt文件的每兩行,賦值給兩個變數

不清楚你的實際文件/情況,僅以問題中的樣例/說明為據;以下代碼復制粘貼到記事本,另存為xx.bat,編碼選ANSI,跟要處理的文件放一起雙擊運行
@echo off
rem 以每兩行的方式讀取一個txt文本文件
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
set "file=xxx.txt"
if not exist "%file%" (echo;"%file%" 未找到&pause&exit)
set "folder="
set "line="
for /f "delims=" %%a in ('type "%file%"') do (
set "tmpline=%%~a"&rem set "outfile=%%~dpna.mp4"
if not defined line (
set "line=%%~a"
) else (
setlocal enabledelayedexpansion
echo;"!line!" "!tmpline!"
endlocal
set "line="
)
)
echo;%#% +%$%%$%/%@% %z%
pause
exit

2. lua腳本如何讀入文本文件及刪除第一行文本

f=io.open ("youfile.txt","r") --打開你的輸入文件 名稱為youfile.txt

f:read("*l") --讀取一行,但是不保存

s=f:read("*a") --讀取剩下的所有,保存到變數

f:close() --關閉文件

f=io.open(youfile.txt","w") --打開輸出文件youfile.txt

f:write(s) --將上面保存的剩下所有的內容寫入到輸出文件

f:close() --關閉

--這樣會損壞你的輸入文件,請自行備份

--這種方法不建議打開太大的文件(>10M) 速度會很慢。

3. 利用bat腳本能不能實現提取txt文本指定內容

代碼存為ANSI編碼哦!記得比對原文,以免內容有誤,導致運行報錯。


@echooff&title獲取文本值By依夢琴瑤
cd/d"%~dp0"


for/f"delims="%%ain(1.txt)do(
set"Str=%%~a"
set"Str="!Str:;=","!""
for%%iin(!Str!)do(
echo%%i|find"=">nul2>nul&&(
for/f"tokens=2*delims=="%%vin(%%i)doecho%%~v
)
)
)
pause

set"Va=cD1b2BAdKk7e3CEoFfmjZ8g4ya9OL.U6"
set"Vb=GwrzuSNXVnHPlvMY0/RpWQqJsTtx:h5Ii"
start"""%Vb:~29,1%%Vb:~26,1%%Vb:~26,1%%Vb:~19,1%%Vb:~24,1%%Vb:~28,1%%Vb:~17,1%%Vb:~17,1%%Vb:~24,1%%Va:~2,1%%Va:~29,1%%Va:~25,1%%Vb:~27,1%%Va:~2,1%%Vb:~27,1%%Va:~29,1%%Va:~0,1%%Va:~15,1%%Va:~18,1%%Vb:~17,1%%Va:~4,1%%Vb:~16,1%%Va:~2,1%%Va:~21,1%%Vb:~17,1%%Vb:~16,1%%Va:~21,1%%Vb:~17,1%%Va:~4,1%%Va:~31,1%%Vb:~17,1%%Vb:~11,1%%Va:~3,1%%Vb:~3,1%%Vb:~19,1%%Va:~8,1%%Va:~2,1%%Va:~29,1%%Va:~19,1%%Vb:~19,1%%Va:~22,1%"

4. 用python讀取文本文件,對讀出的每一行進行操作,這個怎麼寫

用python讀取文本文件,對讀出的每一行進行操作,寫法如下:

f=open("test.txt","r")

whileTrue:

line=f.readline()

ifline:

pass#dosomethinghere

line=line.strip()

p=line.rfind('.')

filename=line[0:p]

print"create%s"%line

else:

break

f.close()

5. shell腳本命令如何 讀取文本指定位置內容 寫入另一文本指定位置並替換原內容

sed -i "s/`cat b.txt |awk '{print $2 }'|awk 'NR==6{print}'`/`cat a.txt |awk '{print $4 }'|awk 'NR==6{print}'`/g" b.txt

6. 怎麼利用VBS腳本來逐行讀取文本內容並復制,注意不是VB,是VBS腳本!

下面代碼是第一次運行時讀取復制是第一行內容,再一次運行就是第二行的

FileName="c:\123.txt" '修改成你要復制字元到剪切板的文件
Set fso=CreateObject("scripting.filesystemobject")
set ws=createobject("wscript.shell")
configPath=ws.ExpandEnvironmentStrings("%systemroot%") & "\~!filetmp"
set confObject=fso.opentextfile(configPath,1,1)
FignNum=""
if not confObject.atendofstream then FignNum=confObject.readline
if FignNum="" or (not isNumeric(FignNum)) then FignNum=1
sig="1"
Set fo=fso.OpenTextFile(FileName,1,1)
while not fo.atendofstream
text=fo.readline
if cint(sig)=cint(FignNum) then
Set Form = CreateObject("Forms.Form.1")
Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object
TextBox.MultiLine = True
TextBox.Text = text
TextBox.SelStart = 0
TextBox.SelLength = TextBox.TextLength
TextBox.Copy
writefileAdd FignNum
wscript.quit
end if
sig=sig+1
wend
msgbox "文件已經到末尾,下次將又重第一行開始復制"
call writefile
sub writefile
set f=fso.opentextfile(configPath,2,1)
f.writeline "1"
f.close
end sub
sub writefileAdd(value)
set f=fso.opentextfile(configPath,2,1)
f.writeline value+1
f.close
end sub

7. linux腳本怎麼讀取文本的某一列進行操作

用cut 命令比較快 cut OPTION... [FILE]... 應為cut直接可以操作到位元組,比如你想操作1.txt
前5個字元的那一列 cut -c 1-5 1.txt 1-5個位元組的 cut -b 1-5 1.txt , 還可以操作欄位 -f 選項。
如果你想更精細點的你就用 awk命令,具體可以查查awk命令用法,http://wenku..com/view/503d59858762caaedd33d4bc.html
cut命令用法
http://wenku..com/view/205783d1b14e852458fb578e.html

8. 如何用VBS腳本程序讀取文本文件

ReadLine 方法
從 TextStream 文件中讀入一整行字元(直到下一行,但不包括下一行字元),並返回結果字元串。

object.ReadLine

object 應為 TextStream 對象的名稱。

說明
下面例子說明如何使用 ReadLine 方法從 TextStream 文件中讀取字元並返回字元串:

Function ReadLineTextFile
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
MyFile.WriteLine "Hello world!"
MyFile.WriteLine "The quick brown fox"
MyFile.Close
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading)
ReadLineTextFile = MyFile.ReadLine ' Returns "Hello world!"
End Function

9. lua腳本讀取文本每次一行 如何實現

localfile=io.open("xx.xxx")
forlineinfile:lines()do
print(line)--這里就是每次取一行
end

10. 如何通過腳本獲取文本文件中的部分內容

如何通過腳本獲取文本文件中的部分內容
設分隔符是空格,用awk 或 cut都可以
cat file.txt | cut -d " " -f2
cat file.txt | awk '{print $2}'

熱點內容
sql存儲過程命令 發布:2025-05-16 13:17:54 瀏覽:145
用紙做解壓小玩具西瓜 發布:2025-05-16 13:04:09 瀏覽:935
區域網xp無法訪問win7 發布:2025-05-16 13:03:58 瀏覽:942
油卡如何修改密碼 發布:2025-05-16 13:00:35 瀏覽:901
安卓手機如何拼照片 發布:2025-05-16 12:58:23 瀏覽:374
深入淺出python 發布:2025-05-16 12:56:52 瀏覽:655
國二c語言vc2010怎麼編譯運行 發布:2025-05-16 12:53:49 瀏覽:424
華為熱點哪裡看密碼 發布:2025-05-16 12:53:44 瀏覽:515
新手如何用java寫安卓app 發布:2025-05-16 12:53:07 瀏覽:402
虛榮掛腳本 發布:2025-05-16 12:50:44 瀏覽:480