删除空白/尾随 [英] Remove whitespace/trailing

查看:130
本文介绍了删除空白/尾随的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行下面的命令写入当前的IPv4地址到日志文件:

  IPCONFIG | FINDSTR的IPv4>>C:\\ ip.log

不过,也有一些空格,我怎么能删除那些?

  IPv4地址。 。 。 。 。 。 。 。 。 。 。 :10.0.0.15
   IPv4地址。 。 。 。 。 。 。 。 。 。 。 :172.16.0.15
   IPv4地址。 。 。 。 。 。 。 。 。 。 。 :192.168.0.15

感谢。


解决方案

@ECHO OFF
SETLOCALFOR / F令牌= 1 * delims =%%一个IN('IPCONFIG ^ | FINDSTR的IPv4')DO(
 FOR / F %% c。在(%% B)DO ECHO ++ %% C ++
)GOTO:EOF

当然,回声可以是一个设置,如果你愿意的话。在 ++ 无论是数据的结束仅仅是为了表明该空间已被删除。

查找来自 IPCONFIG 命令的目标线(S),选择部分超出了:在这些线上 ,并处理结果字符串,删除蚂蚁空间(默认分隔符 FOR / F %%ç

I'm executing the following command to write the current IPv4 address to a logfile:

ipconfig | findstr IPv4>>"c:\ip.log"

However, there are some whitespaces, how can I remove those?:

   IPv4 Address. . . . . . . . . . . : 10.0.0.15
   IPv4 Address. . . . . . . . . . . : 172.16.0.15
   IPv4 Address. . . . . . . . . . . : 192.168.0.15

Thanks.

解决方案

@ECHO OFF
SETLOCAL

FOR /f "tokens=1*delims=:" %%a IN ('ipconfig^|findstr "IPv4" ') DO (
 FOR /f %%c IN ("%%b") DO ECHO ++%%c++
)

GOTO :EOF

Naturally, the echo could be a set if you so desire. The ++ either end of the data is merely to show that the spaces have been removed.

Find the target line(s) from an ipconfig command, select that part beyond the : on those lines, and process the resultant string, removing ant spaces (default delimiters in the for /f %%c)

这篇关于删除空白/尾随的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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