小编Ara*_*ash的帖子

计算文件第一列中的出现次数

我们有这个文件:

1 2 
1 3
1 2
3 3
52 1
52 300
Run Code Online (Sandbox Code Playgroud)

和 1000 多个。

我想计算每个值在第一列中出现的次数。

1  3 
3  1
52 2
Run Code Online (Sandbox Code Playgroud)

这意味着我们看了1三遍。

在 Perl、AWK 或 Bash 中,我该怎么做?

linux bash perl awk

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

删除文件每一行中的重复项

如何删除每一行中的重复项,例如这里?

1 1 1 2 1 2 3
5 5 4 1 2 3 3
Run Code Online (Sandbox Code Playgroud)

我想得到这个输出:

1 2 3 
5 4 1 2 3
Run Code Online (Sandbox Code Playgroud)

有很多行(100,000),在每一行中我都想要唯一的值。Perl 可能是最快的,但我怎样才能在 Perl 或 Bash 中做到呢?

linux bash perl uniq

7
推荐指数
2
解决办法
2950
查看次数

输出出现2次以上的项目

如何选择出现 4 次或更多的 ip,例如这里?

输入文件是

192.168.1.28
192.168.1.100
192.168.1.31
192.168.101.2
192.168.1.31
192.168.11.02
192.168.1.31
192.168.1.28
192.168.1.28
192.168.1.31
192.168.21.31
192.168.1.28
192.168.1.31
Run Code Online (Sandbox Code Playgroud)

然后我想得到这个输出:

192.168.1.28
192.168.1.31  
Run Code Online (Sandbox Code Playgroud)

首选使用 AWK

谢谢你们!:)

bash shell awk bash-scripting

4
推荐指数
2
解决办法
6541
查看次数

使用 shell 脚本或 awk 从文件中提取字符串

我有一个包含一些网站的 txt 文件。我想提取网站我该怎么做?

xhr_object.open("GET",filename,false );
<li><a href="http://www.dakar.com" TARGET=_BLANK>dakar.com</a></li>
<a href="http://www.docomolabs-usa.com/" TARGET="other"><img src="art/docomo.gif" width="104" height="80" align="middle" border="0" alt="NTT Docomo"></a>
<a href="http://www.google.com/" TARGET="other"><img src="art/google.gif" width="121" height="50" align="middle" border="0" alt="Google"></a>
<a href="http://www.hpl.hp.com/" TARGET="other"><img src="art/hp_
<a href="http://www.ibm.com/" TARGET="other"><img src="art/ibmlogo.gif" width="100" height="38" align="middle" border="0" alt="IBM"></a>
<a href="http://research.microsoft.com/" TARGET="other"><img src="art/microsoft.gif" width="135" height="50" align="middle" border="0" alt="Microsoft Research"></a>
<a href="http://www.vmware.com/" TARGET="other"><img src="art/vmware.gif" width="140" height="40" align="middle" border="0" alt="vmware"></a>
function domainForHostname(hostname) {
Vary: Host
Allow: GET
Run Code Online (Sandbox Code Playgroud)

和输出:

http://www.dakar.com
http://www.docomolabs-usa.com/
http://www.google.com/
http://www.hpl.hp.com/
http://www.ibm.com/
http://research.microsoft.com/
http://www.vmware.com/
Run Code Online (Sandbox Code Playgroud)

编辑:另一个输入示例

Host: mail.google.com
Host: mail.google.com
GET …
Run Code Online (Sandbox Code Playgroud)

linux shell awk

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

awk 中的匹配字符串

如何搜索文件以查找具有 SRC= 的行,例如此处?我的意思是我如何使用 awk 在这个文件中找到源 IP 地址,例如

Mar 10 03:17:12 ubuntu kernel: [11045.721649] Type=ScanXMASIN=eth0 OUT= MAC=00:0c:29:a1:51:1c:00:0c:29:23:9d:e4:08:00 SRC=192.168.1.28 DST=192.168.1.27 LEN=40 TOS=0x00 PREC=0x00 TTL=47 ID=6603 PROTO=TCP SPT=47301 DPT=53 WINDOW=1024 RES=0x00 URG PSH FIN URGP=0 
Mar 10 03:17:12 ubuntu kernel: [11045.721702] Type=ScanXMASIN=eth0 OUT= MAC=00:0c:29:a1:51:1c:00:0c:29:23:9d:e4:08:00 SRC=192.168.1.30 DST=192.168.1.27 LEN=40 TOS=0x00 PREC=0x00 TTL=42 ID=6802 PROTO=TCP SPT=47301 DPT=5900 WINDOW=1024 RES=0x00 URG PSH FIN URGP=0 
Mar 10 03:17:32 ubuntu kernel: [11065.703937] Type=ScanACKIN=eth0 OUT= MAC=00:0c:29:a1:51:1c:00:0c:29:23:9d:e4:08:00 SRC=192.168.1.31 DST=192.168.1.27 LEN=40 TOS=0x00 PREC=0x00 TTL=40 ID=62992 PROTO=TCP SPT=47301 DPT=1521 WINDOW=1024 RES=0x00 URG PSH …
Run Code Online (Sandbox Code Playgroud)

bash shell awk

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

标签 统计

awk ×4

bash ×4

linux ×3

shell ×3

perl ×2

bash-scripting ×1

uniq ×1