Skip to content

Instantly share code, notes, and snippets.

@dpmccabe
Last active September 15, 2016 16:59
Show Gist options
  • Save dpmccabe/83b78d43bf82b872b397b71412716522 to your computer and use it in GitHub Desktop.
Save dpmccabe/83b78d43bf82b872b397b71412716522 to your computer and use it in GitHub Desktop.
bash snippets
###########################################################################################################################
# commands
###########################################################################################################################
# ls only file size and name
stat -c "%s %n" *.txt | column -t
# watch output of qstat, highlight changes every 5s
watch -n 5 -d 'qstat'
# grep last occurrence of "%" in all logfiles in folder, watch result with highlighting
watch -d -n 10 'for file in *.log; do tac ${file} | grep -m1 %; done'
# create TAR of all PNG files in folder recursively
find thepath/ -name \*.png | tar -cf pngs.tar -T -
# print short hash of current Git commit
git log --pretty=format:'%h' -n 1
# given samples.txt, save TSV (w/ header) of {sample name, BAM file location}
fiss annot_get WorkspaceName sample=`cat samples.txt | paste -sd ','` clean_bam_file_capture > bams.tsv
# match row of TSV by value of any column, retrieve value of second column
sample="asdf"
fcid=`cat bams.tsv | grep $sample | cut -f2`
# given TSV (w/ header) of {sample_id, target file location}, copy target files to local dir
cat targets.tsv | cut -f 2 | tail -n +2 | xargs cp -t targets/
# print list of column headers in TSV
cat file.tsv | grep -v "^#" | head -n 1 | tr '\t' '\n'
###########################################################################################################################
# functions/bash_login utils
###########################################################################################################################
# fresh R session
alias Rscript="Rscript --no-save --no-restore"
alias R="R --no-save --no-restore"
# print head, tail, and head...tail of TSV file
function thead() {
cat $1 | grep -v "^#" | head | column -t
}
function ttail() {
tail $1 | column -t
}
function tht() {
{ cat $1 | grep -v "^#" | head; echo -e "\e[35m...\e[39m"; tail $1; } | column -t
}
# print unique entries in column <i> of TSV file
# c 3 file.tsv
function c() {
cat $2 | grep -v "^#" | cut -f $1 | uniq
}
# colorized `man` output
man() {
env \
LESS_TERMCAP_mb=$(printf "\x1b[38;2;255;200;200m") \
LESS_TERMCAP_md=$(printf "\x1b[38;2;255;100;200m") \
LESS_TERMCAP_me=$(printf "\x1b[0m") \
LESS_TERMCAP_so=$(printf "\x1b[38;2;60;90;90;48;2;40;40;40m") \
LESS_TERMCAP_se=$(printf "\x1b[0m") \
LESS_TERMCAP_us=$(printf "\x1b[38;2;150;100;200m") \
LESS_TERMCAP_ue=$(printf "\x1b[0m") \
man "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment