Skip to content

Instantly share code, notes, and snippets.

@avli
Created October 21, 2021 15:10
Show Gist options
  • Save avli/981702aee5a399c6e4a1c38d047c2a86 to your computer and use it in GitHub Desktop.
Save avli/981702aee5a399c6e4a1c38d047c2a86 to your computer and use it in GitHub Desktop.
#!/use/bin/env perl
use strict;
# Usage:
# ls -l <path> | perl lsbasename.pl
while (<STDIN>) {
chomp;
my $original = $_;
my @chunks = split / /;
my $fullpath = $chunks[-1];
my $basename = (split /\//, $fullpath)[-1];
$original =~ s/$chunks[-1]/$basename/;
print $original . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment