zoukankan      html  css  js  c++  java
  • 字符串整形

    从网上拿到hosts记录,然后将它整形输出成address=/www.google.com/127.0.0.1这种格式。

    第一个办法有点偷懒,只找出URL列,然后手动在最后加上IP地址。误打误撞学到了Trim的特殊之处。

    第二个办法老老实实把URL列和IP列交换位置,然后输出。

    <#方法一#>
    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/vokins/yhosts/master/hosts').content -split "`n"
    ($result | Select-String -Pattern "^127.0.0.1").Line | foreach { 
      'address=/' + $_.TrimStart('.1270').TrimStart() + '/127.0.0.1'
    }
    <#方法二#>
    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/vokins/yhosts/master/hosts').content -split "`n"
    ($result | Select-String -Pattern "^127.0.0.1").Line | foreach {
      'address=/' + ($_ -split " ")[1] + "/" + ($_ -split " ")[0]
    }

    将诸如"google.com": 1,这样格式的文本整形成server=/google.com/127.0.0.1#5353输出

    $result = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/1265578519/PAC/master/abc.pac').content -split "`n"
    ($result | Select-String -Pattern "`".+`":s1").Line.Trim('",1: ') | foreach {
      'server=/' + $_ + "/127.0.0.1#5353"
    }

    将诸如apnic|CN|ipv4|203.34.39.0|256|20110414|allocated这样格式的文本整形输出成192.168.1.0/24

    $result = (Invoke-WebRequest -Uri 'http://ftp.apnic.net/stats/apnic/delegated-apnic-latest').content -split "`n"
    ($result | Select-String -Pattern ".+CN[|]ipv4[|].+").Line | foreach {
      '-A SHADOWSOCKS -d ' + $_.split('|')[3] + '/' + (32 - [math]::log($_.split('|')[4]) / [math]::Log(2)) + ' -j RETURN'
    }
  • 相关阅读:
    jsmin Javascript 的小巧的压缩工具
    pChart 支持中文显示
    使用 SyntaxHighlighter 实现代码高亮
    Linux Ubuntu 下阅读 CHM
    QueryPath Method Summary_方法速查手册
    QueryPath PHP 中的 jQuery
    SQL SELECT DISTINCT 语句
    写网页内容需要注意些什么?
    jQuery UI 弹出注册窗口_练习
    Smarty 中的 Foreach
  • 原文地址:https://www.cnblogs.com/IvanChen/p/6598555.html
Copyright © 2011-2022 走看看