Skip to content

Instantly share code, notes, and snippets.

@jschnasse
Last active May 20, 2020 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jschnasse/c320af2187e46c4aad1a8c19407fdd0c to your computer and use it in GitHub Desktop.
Save jschnasse/c320af2187e46c4aad1a8c19407fdd0c to your computer and use it in GitHub Desktop.
Convert `ls -l` to csv
#! /bin/bash
_space_="\ *";
type=".";
perm="[^\ ]*";
hlinks=$perm;
user=$perm;
group=$perm;
size=$perm;
modified=".{12}";
name=".*";
REGEX="^($type)"
REGEX=${REGEX}"($perm)"
REGEX=${REGEX}"$_space_"
REGEX=${REGEX}"($hlinks)"
REGEX=${REGEX}"$_space_"
REGEX=${REGEX}"($user)"
REGEX=${REGEX}"$_space_"
REGEX=${REGEX}"($group)"
REGEX=${REGEX}"$_space_"
REGEX=${REGEX}"($size)"
REGEX=${REGEX}"$_space_"
REGEX=${REGEX}"($modified)"
REGEX=${REGEX}"$_space_($name)"
ls -l $@ | \
sed -r -e s/"$REGEX"/'"\1","\2","\3","\4","\5","\6","\7","\8"'/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment