car.txt打開是這樣
Toyota
Honda
BMW
AUDI
Mercedes Benz
位置是這個C:\car123\car.txt
select start with letter "A", "B", "C" from car.txt
顯示的車名字用,分開
根據上面的討論
Windows (Powershell):
(Select-String -Path "car.txt" -Pattern "[A|B|C]" -CaseSensitive).Line -join ","
Linux/Mac (shell):
grep '[A|B|C]' car.txt | tr '\n' ',' | sed 's/,$//' && echo
看你的標籤應該是要使用Python
with open('C:\car123\car.txt', 'r') as f:
result = list()
for line in f.readlines():
if line[0] in ['A', 'B', 'C']:
result.append(line.strip())
print(','.join(result))