Skip to content

Instantly share code, notes, and snippets.

@nickjacob
Created January 24, 2014 05:44
Show Gist options
  • Save nickjacob/8592571 to your computer and use it in GitHub Desktop.
Save nickjacob/8592571 to your computer and use it in GitHub Desktop.
bash function to prepend text to output of script (example use in here too)
function label_stream()
{
perl -sne '$|=1; print "[$cmd]\t$_"' -- -cmd="$1"
}
# example use
ls -lafh . | label_stream "ls"
# output
[ls] drwxr-xr-x 6 nickjacob staff 204B Nov 11 2012 Processing/
[ls] drwxr-xr-x 6 nickjacob staff 204B Dec 4 2012 progress/
[ls] drwxr-xr-x 5 nickjacob staff 170B Nov 19 2011 Projects/
[ls] drwxr-xr-x 3 nickjacob staff 102B Oct 24 00:10 queer_1.oo3/
[ls] drwxr-xr-x 3 nickjacob staff 102B Dec 8 13:10 Queer_Final.oo3/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment