Carpenter Carpenter - 1 year ago 68
Linux Question

Adding an || regex to a bash ``ed one-liner in a perl script

I am trying to add an || regex to a bash ``ed one-liner in a perl script, if that makes any sense.

my $result = `df -H | grep -vE '^Filesystem|tmpfs|cdrom|none' | awk '{ print \$1 "\t" \$5 " used."}'`;

# .Private maybe the same as /dev/sdb1 so I'm trying to remove it too
# by trying to add || (m/\.Private/) to the above

print "$result";

So I am removing lines from the output that start with Filesystem, tmpfs, cdrom or none, at present, but I would also like to and the "or lines containing .Private" to the one-liner, if possible...

I have the below also, but want to reproduce its results with the above code...

my @result2 =Shell::df ("-H");
shift @result2; # get rid of "Filesystem..."
for( @result2 ){
next if ((/^tmpfs|tmpfs|cdrom|none/) || (m/\.Private/));
my @words2 = split('\s+', $_);
print $words2[0], "\t", $words2[4], " used\.\n";

Answer Source

You just need to add the \.Private part to the current regexp:

grep -vE '^Filesystem|tmpfs|cdrom|none|\.Private'

On a side note, the pattern ^Filesystem|tmpfs|cdrom|none might not actually do what you want, as only Filesystem is matched at the beginning of the line, the other parts will be matched if they appear anywhere in the input. To match them at the beginning, change it to:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download