Skip to content

Instantly share code, notes, and snippets.

@apuignav
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save apuignav/54cd2f75df01615172c0 to your computer and use it in GitHub Desktop.

Select an option

Save apuignav/54cd2f75df01615172c0 to your computer and use it in GitHub Desktop.
Useful scripts from Christian Neukirchen's Summer of Scripts (http://chneukirchen.org/blog/)
#!/usr/bin/perl
# From http://chneukirchen.org/blog/archive/2013/07/summer-of-scripts-f.html
my $field = shift or usage();
$field -= 1 if $field > 0;
while (<>) {
chomp;
my @f = split;
print $f[$field], "\n";
}
sub usage {
print STDERR "$0 fieldnumber\n";
exit 1;
}
#!/bin/sh
# total - sum up numbers in a column
# From http://chneukirchen.org/blog/archive/2013/07/summer-of-scripts-total.html
expr "$1" : -F >/dev/null && F=$1 && shift
exec awk $F -v f=${1:-1} '{s+=$f} END{print s}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment