小编cap*_*ian的帖子

在一行中返回正则表达式搜索的第二个实例

我有一个具有特定兴趣行(例如,第12行)的文件,如下所示:

conform: 244216 (packets) exceed: 267093 (packets)
Run Code Online (Sandbox Code Playgroud)

我编写了一个脚本来通过正则表达式提取第一个数字并将值转储到一个新文件中:

getexceeds = open("file1.txt", "r").readlines()[12]
output = re.search(r"\d+", getexceeds).group(0)

with open("file2.txt", "w") as outp:
    outp.write(output)
Run Code Online (Sandbox Code Playgroud)

我还不够好将该行中的第二个数字返回到一个新文件中 - 有人可以提出建议吗?

一如既往地感谢您的帮助!

python regex readlines

5
推荐指数
2
解决办法
6255
查看次数

如何将表单拆分为两列?

我有一个基本的表单,将输入传递给PHP脚本.我想拆分表单,以便第二个子条目(Person 2)位于第一个(Person 1)右侧的列中,而不是直接位于下面.

<link rel="stylesheet" href="test.css">    
    <form class="form-validation" method="post" action="script.php">
       <link rel="stylesheet" href="test.css">
       <h2>Person 1:</h2>
       <br>
       <div class="form-row form-input-name-row">
          <label>
          <span>Name</span>
          <input name="field1" type="text">
          </label>
       </div>
       <div class="form-row form-input-name-row">
          <label>
          <span>Age</span>
          <input name="field2" type="text">
          </label>
       </div>
       <div class="main-content">
          <h2>Person 2:</h2>
          <br>
          <div class="form-row form-input-name-row">
             <label>
             <span>Name</span>
             <input name="field3" type="text">
             </label>
          </div>
          <div class="form-row form-input-name-row">
             <label>
             <span>Age</span>
             <input name="field4" type="text">
             </label>
          </div>
    </form>
    <div>
    <button name="submit">Submit form</button>
    </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

html css forms

5
推荐指数
1
解决办法
1万
查看次数

运行目录中的所有文件,使用AWK单独处理每个文件

我想在目录中的每个文件上运行一个AWK脚本,但是AWK命令必须只在该文件中运行 - 也就是说,它在定义的RS之间搜索并返回它应该的内容,但我需要它在它停止时到达一个文件的末尾,并在下一个文件的开头再次开始.

我有这个运行,它可以单独处理每个文件:

awk '!/value1|value2/ && NF {print FILENAME " - " RS,$1}' RS="value" file1 > result.txt
Run Code Online (Sandbox Code Playgroud)

但是,当使用时将输出应用于目录中的每个文件时输出不正确

find . -type f | awk ... file1 > result.txt
Run Code Online (Sandbox Code Playgroud)

我如何让它分别查看每个文件,但将结果附加到同一个文件中?不幸的是我不知道.我想这是通过将每个文件添加到变量中并让AWK查看它,但我不知道该怎么做.

文件file1:

interface Vlan3990
 ip address 172.17.226.23 255.255.255.254
Run Code Online (Sandbox Code Playgroud)

文件文件2:

version 12.2
ip tacacs source-interface Loopback99
ip vrf test
 description xx
interface Loopback99
 description Management Loopback
interface Loopback100
 shutdown
Run Code Online (Sandbox Code Playgroud)

产量

find . -type f | xargs awk '!/description|shutdown/ && NF {print FILENAME " - " RS,$1}' RS="interface" | more
./file1 - interface …
Run Code Online (Sandbox Code Playgroud)

variables search awk file

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

awk ×1

css ×1

file ×1

forms ×1

html ×1

python ×1

readlines ×1

regex ×1

search ×1

variables ×1