我想阅读以 ( ; ) 分号字符结尾的 txt 文件的内容
I would like to read content of txt file ends it with ( ; ) semi-colon character
我的 txt
文件在 LINE1 中有 50 个长字符,但我只想读取前 10 个字符,有时是 11 个或更少的字符,并以分号结尾。
基本上,我想获取分号前的字符。
First.txt
1234567891;45416564653afsd
Second.txt
124562;455466asdfa
感谢任何人的帮助..
在python中:
file = open('input.txt', 'r')
while True:
c = file.read(1)
if c == ';':
break
# Ensure loop break at EOL
if not c:
break
print("Character: " + c)
以下 returns 来自输入文件 File
的每一行在第一行 ;
之前的部分。
如果没有 ;
则返回整行。
Get-Content File | ForEach-Object { ($PSItem -split ';')[0] }
为了让您感受到 PowerShell 的弹性,您可以使用内置别名将以下内容重写为更简洁的形式(尽管最好是冗长并避免在 脚本中使用别名):
gc File | % { ($_ -split ';')[0] }
我的 txt
文件在 LINE1 中有 50 个长字符,但我只想读取前 10 个字符,有时是 11 个或更少的字符,并以分号结尾。
基本上,我想获取分号前的字符。
First.txt
1234567891;45416564653afsd
Second.txt
124562;455466asdfa
感谢任何人的帮助..
在python中:
file = open('input.txt', 'r')
while True:
c = file.read(1)
if c == ';':
break
# Ensure loop break at EOL
if not c:
break
print("Character: " + c)
以下 returns 来自输入文件 File
的每一行在第一行 ;
之前的部分。
如果没有 ;
则返回整行。
Get-Content File | ForEach-Object { ($PSItem -split ';')[0] }
为了让您感受到 PowerShell 的弹性,您可以使用内置别名将以下内容重写为更简洁的形式(尽管最好是冗长并避免在 脚本中使用别名):
gc File | % { ($_ -split ';')[0] }