[关闭]
@nrailgun 2016-09-19T21:25:52.000000Z 字数 688 阅读 1426

Shell Tricks

程序设计


Iterate in 2 files

  1. while read i <&3 && read j <&4; do
  2. # op $i $j
  3. done 3<$IFILE 4<&JFILE

Every 3 line

  1. awk 'NR % 3 == 0' myfile

Be careful with lasting backslash

  1. caffe train solver.prototxt
  2. --weights=iter_1000.caffemodel

It will be executed! And finally you will find out caffe didn't load any thing!

List full path

  1. ls -d -1 ${PWD}/dir

Find out intersectino

  1. sort f1 f2 | uniq -d

Wait for children

  1. for job in `jobs -p`; do
  2. wait $job
  3. done

Conditional execution

  1. if [[ ${#FILES} -le $THREDHOLD ]]; then
  2. # ...
  3. else
  4. # ...
  5. fi

Use -e to test if a file exists.

Brackets

$(cmd) to execute cmd, $((j + i)) to execute expression, ${var} to expand variables.

Glob strip

  1. # Strip prefix (greedy)
  2. filename=${VARIABLE_NAME##PREFIX}
  3. # Strip postfix (non-greedy)
  4. dirname=${VARIABLE_NAME%POSTFIX}

Merge 2 files line by line

  1. paste f1 f2
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注