有了这个 awk 单行
awk '{lines[NR]=$0}{for(i=0;i<3;i++) print $lines[i]}
awk.write
awk.write
this line 1 no un1x
this lines 22 0
butbutbut this 33 22 has unix
but not 1
THIS is not
butbutbut ffff
second line
Run Code Online (Sandbox Code Playgroud)
打印为
this line 1 no un1x
this line 1 no un1x
this line 1 no un1x
this lines 22 0
this lines 22 0
this lines 22 0
butbutbut this 33 22 has unix
butbutbut this 33 22 has unix
butbutbut this 33 22 has unix …
Run Code Online (Sandbox Code Playgroud) 我有一个案例,我需要一个文件post-process
.样本格式如下: -
bigspeedpro.com Intel::DOMAIN from http://malc0de.com/bl/BOOT via intel.criticalstack.com F
1.1.1.1 Intel::DOMAIN from http://abcd.com/bl/BOOT via intel.criticalstack.com F
Run Code Online (Sandbox Code Playgroud)
预期产量为: -
1.1.1.1 abcd
Run Code Online (Sandbox Code Playgroud)
解析如下: -
如果以IP地址开头
from
来 F
替换它我想使用,sed但我不知道如果sed
可以用来匹配多个字符串,例如malc0de或abc或许我需要一个更完整的脚本然后只是一行存储字符串值在数组中.任何的想法?顺便说一句,使用的例子sed
最受欢迎.
至今
d
在sed中使用我可以删除行并将输出重定向到文件Run Code Online (Sandbox Code Playgroud)\#!/bin/bash sed -i s/\[a-zA-Z]\/d test ./infile > testme.txt sed -i s/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/s+\Intel::DOMAIN\\s*from(.*?)\s+F\1malc0de
或者我想保存像ARRAY =(malc0de abcd)
然后代替捕获组我可以做$ {ARRAY [2]}它会起作用吗?或者我可以做一些像.net子串匹配之间的东西 from
和F
我复制结果的字符串变量.然后搜索我的字符串,例如malc0de,如果找到替换匹配结果的搜索模式?但我不知道bash ......
更新 使用awk脚本我很干净
Run Code Online (Sandbox Code Playgroud)1.1.1.1 www.abc.com 1.1.2.2 def.com 2.2.2.2 mnx.dbc.net
但是,我希望将ip地址后的第二列缩短为我自己选择的字符串,例如在第二列中我只接受
abc def …