Windows批处理文件分隔符之后删除文本 [英] Windows Batch file to remove text after a delimiter

查看:151
本文介绍了Windows批处理文件分隔符之后删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法创建一个批处理文件,它接受一个文件 file.txt的和一个分隔符后,将删除这些文字,并创建与修改的新文件。

I'm having trouble creating a batch file that takes a file file.txt and removes the text after a delimiter and creates a new file with the changes.

例如:

file.txt的将包含:

ashlasfj/asdkasdkj/asdkjasd
jhsdkfjhsdf/ajhsjduias/asjhfhsd

newfile.txt 将保留一切之前的第一个 /

the newfile.txt would keep everything prior to the first /:

ashlasfj
jhsdkfjhsdf

我想用一个for循环的:

I was thinking of using a for loop:

FOR / F令牌= 1,* delims = /%%的A(test.txt的)做(
    这里的东西

for /f "tokens=1,* delims=/" %%A in (test.txt) do ( something here )

推荐答案

试试这个:

@echo off
setlocal

for /f "tokens=1 delims=/" %%a in (test.txt) do (echo %%a >> newfile.txt)

这篇关于Windows批处理文件分隔符之后删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆