Skip to content

Instantly share code, notes, and snippets.

@kyanny
Last active August 24, 2022 15:10
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 kyanny/d44a3fceeca22e76811744e8809e9602 to your computer and use it in GitHub Desktop.
Save kyanny/d44a3fceeca22e76811744e8809e9602 to your computer and use it in GitHub Desktop.
lcut() {
local input
if [ -p /dev/stdin ]; then
input=$(cat -)
else
input=$(cat $1)
shift
fi
echo $input | perl -slane '@pairs = /(\w+=?(?:"[^"]*"|[^\s]*))/g;
@keys = split /\s+/, $args;
foreach $key (@keys) {
foreach $pair (@pairs) {
($k, $v) = split /=/, $pair;
print $pair if $key eq $k;
}
}' -- -args="$*"
}
lfmt() {
local input
if [ -p /dev/stdin ]; then
input=$(cat -)
else
input=$(cat "$@")
fi
echo $input | perl -pe 's/(\w+=?(?:"[^"]*"|[^\s]*))/\n$1/g'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment