Skip to content

Instantly share code, notes, and snippets.

@Gen2ly
Created June 1, 2012 15:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gen2ly/2853011 to your computer and use it in GitHub Desktop.
Save Gen2ly/2853011 to your computer and use it in GitHub Desktop.
Output file without comments or blanklines
#!/bin/bash
# Output file without comments or blanklines
# Display usage if no parameters given
if [ -z $1 ]; then
echo " ${0##*/} <*c> <filename> - print file w/o comments/blanklines - (c)lipboard"
exit 1
fi
case $1 in
# Copy output to xorg server clipboard
c ) shift
# Check if selection exists
if [ ! -f "$@" ]; then
echo " Selection \""$@"\" does not exist." && exit
fi
# Exit if root (root doesn't have access to user xorg server)
if [[ `whoami` == root ]]; then
echo " Copying to clipboard cannot be user root" && exit
else
grep -vh '^[[:space:]]*\(#\|$\)' "$@" | xclip -selection c
echo " Comments stripped from file and copied to xorg server clipboard"
fi
;;
# Print output to terminal
* ) if [ ! -f "$@" ]; then
echo " Selection \""$@"\" does not exist." && exit
fi
grep -vh '^[[:space:]]*\(#\|$\)' "$@" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment