【发布时间】:2015-06-01 23:12:30
【问题描述】:
您好,我正在编写一个脚本,它需要使用 awk 命令对输出的第 6 列进行 grep,但正在获取其他输出。 perl 中使用 awk 提取第 6 列的确切语法是什么?
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my $filesystem=`df -h |grep -i dev|grep -vE '^Filesystem|proc|none|udev|tmpfs'`;
print "(\"$filesystem\"|awk '{print \$6}')"
Output :
7831c1c4be8c% ./test.pl
("/dev/disk1 112Gi 43Gi 69Gi 39% 11227595 18084674 38% /
devfs 183Ki 183Ki 0Bi 100% 634 0 100% /dev
"|awk '{print $6}')%
我正在尝试删除 % 怎么办?
7831c1c4be8c% cat test.pl
#!/usr/bin/perl
use warnings;
use strict;
open my $FS, q(df -h |) or die $!;
while (<$FS>) {
print +(split)[4], "\n"
if /dev/i and not /devfs/;
}
7831c1c4be8c% ./test.pl
40%
【问题讨论】:
-
你在 perl 中使用 awk 的原因是什么?
-
给我们一些输入数据和你喜欢的数据。我想只使用
grep或awk就可以解决这个问题