Just some useful things that I can never remember:
- sed -i 's/str1/str2/g' file.ext (use "" if argument contains a variable)
- ncrcat files.nc catfile.nc
- Find string (case-insensitive) in files of specified type (here .f):
- find . -name '*\.f' |xargs grep -r "string"
- Number of files matching pattern 'pat*':
- find . -maxdepth 1 -type f -name 'pat*' | wc -l
- Number of empty files in present directory:
- find . -maxdepth 1 -empty -type f | wc -l
- Search only in non-binary files of all types:
- find . -type f -print | xargs file | grep text | cut -f1 -d: | xargs grep -ir "some string"
- Number of days in month $mm, year $yy:
- dmax=$(cal ${mm} `date +${yy}` | egrep -v '[A-Za-z]' | wc -w);
- rsync -a -e ssh storethis/ uname@ip:storehere/
- LSF stuff:
- Create group: bgadd -L 5 /groupname
- Modify number of jobs in group: bgmod -L 1 /groupname
- List group stats: bjgroup -s /groupname
- Submit into group with bsub flag: bsub -g /groupname
- Change queue: bswitch swell 29394929
- Delete group: bgdel /groupname
- Detailed job info: bjobs -l 9292929
- ps/eps whitespace cropping:
- ps2eps -B -C < input.ps > output.ps
- eps2eps Figure.eps Figure_Cropped.eps
- ps2epsi input.eps output.eps
- Simple PDF concatenation:
- pdftk input1.pdf input2.pdf cat output output.pdf
- Extract first word/number from each line of a file:
- sed 's/ .*//' file
- cat filename | cut -d " " -f1
- Extract only integers from file:
- grep -E '^[0-9]+$' in.txt > out.txt
- Replace DOS ^M carriage returns with newline character:
- tr '\015' '\n' < input_file > output_file
- Bulk rename:
- ls *txt|sed 's/\(.*\)\.txt/mv \1.txt \1.m/'|sh
- Find missing files from pairs (here, d+ -> single integer delimiter):
- for fname in dep*.nc; do nums=`echo $fname | perl -wlne 'print $1 if /(\d+)/'`; if [ ! -f fpt.${nums}.nc ];then echo "fpt.${nums}.nc not found";fi; done
- More complicated: for fname in dep.*.nc4; do nums=`echo $fname | perl -wlne 'print $1 if /(\d+\.\d+\.\d+.\d+)/'`; if [ ! -f fpt.${nums}.nc4 ];then echo "fpt.${nums}.nc4 not found";fi; done
- for fname in dep*.nc; do nums=`echo $fname | perl -wlne 'print $1 if /(\d+)/'`; if [ ! -f fpt.${nums}.nc ];then echo "fpt.${nums}.nc not found";fi; done
- Emacs hard-wrap adjustment
- M-x auto-fill-mode
- C-u 72 C-x f
- FFMPEG syntax:
- ffmpeg -f image2 -r 10 -i ./frame%d.png -b 600k ./atriv_hits.avi
- FFMPEG splitting:
- ffmpeg -i atriv_hits_12hr.avi -an -vcodec copy -ss 00:00:02 -t 00:10:08 atriv_hits_12hr_1970-1980.avi
- Circumvent segfault when saving from MATLAB in nodisplay mode:
- set(gcf,'Renderer', 'painters');
- Default to white background in all MATLAB figures:
- set(0,'defaultfigurecolor',[1 1 1])
- Semi-magical debugging in MATLAB:
- dbstop if error
runme(someargument) - Use latexdiff seamlessly with git (assumes you've installed latexdiff):
- Create ~/bin/git-latexdiff.sh with:
- #!/bin/bash
TMPDIR=$(mktemp -d /tmp/git-latexdiff.XXXXXX)
latexdiff "$1" "$2" > $TMPDIR/diff.tex
pdflatex -interaction nonstopmode -output-directory $TMPDIR $TMPDIR/diff.tex
open $TMPDIR/diff.pdf
rm -rf $TMPDIR - Let git run it:
chmod a+x ~/bin/git-latexdiff.sh - Add the following to ~/.gitconfig:
- [difftool.latex]
cmd = ~/bin/git-latexdiff.sh "$LOCAL" "$REMOTE"
[difftool]
prompt = false
[alias]
ldiff = difftool -t latex - To run, do:
- git ldiff somefile.tex
- (compare with the standard method:)
git difftool somefile.tex - Produces this nice PDF: