Board logo

标题: [文本处理] 批处理怎样判断hosts文件最后一行是否换行回车(空行)? [打印本页]

作者: kosoft    时间: 2019-12-7 09:16     标题: 批处理怎样判断hosts文件最后一行是否换行回车(空行)?

如题:,判断hosts文件最后一行是否换行回车(空行)

如果有空行,则再其他 继续追加 屏蔽网址;
如果没有空行,则应该先写入一个 换行回车符(空一行),继续追加 屏蔽网址。。。。

写入空行代码我知道:
  1. echo.>>%windir%\system32\drivers\etc\hosts
复制代码
关键是如何判断 文本文件最后一行是否 有 换行回车(空白行)的判断语句,我不会,还望大家不吝赐教,谢谢!

避免出现以下情形:

如何避免 在 需要对多个网址进行屏蔽中,第一个网址(下面代码中“127.0.0.1 www.baidu.com”) 屏蔽失效。
  1. # Copyright (c) 1993-2009 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. #      102.54.94.97     rhino.acme.com          # source server
  17. #       38.25.63.10     x.acme.com              # x client host
  18. # localhost name resolution is handled within DNS itself.
  19. # 127.0.0.1       localhost
  20. # ::1             localhost 127.0.0.1 www.baidu.com
  21. 127.0.0.1 www.tencent.com
  22. 127.0.0.1 www.qq.com
复制代码

作者: WHY    时间: 2019-12-7 23:00

find 或者 more 就可以了。
find /v "" < a.txt & echo;xxx




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2