投稿

6月, 2018の投稿を表示しています

shellでエラー処理

hogeという関数を実行してエラーした時だけfugaという関数を適応したいとする hoge || fuga でいける。とても簡単。 ぎゃくに、hogeが成功した時だけfugaを実行するためには hoge && fuga で良い。

ファイルの存在確認

ややこしい if [ -e myfile ]; then echo "arimasuyo" fi ではだめ。myfileが展開されないため。変数で指示したいなら if [ -e "myfile" ]; then echo "arimasuyo" fi ANDやORも使うことができる。ちなみに -e の前後などには全てスペースが必要。 if [ -e "myfile" ] && [ -e "myfile2" ] ; then echo "motto arimasuyo" fi if [ -e "myfile" ] || [ -e "myfile2" ] ; then echo "motto arimasuyo" fi さらに、ファイルのサイズが0以上かどうかを判定するときは -sを使う if [ -s "$myfile" ] ; then echo "myfile is size > 0" else echo "myfile is size == 0" fi

joinに失敗

https://qiita.com/taruhachi/items/04ccca5e3bc20ad01791  より join が嫌いだ。並べども並べども join: hoge: is not sorted: とかいうから。これは LANG の設定の問題で、 sort 時と join 時の言語設定により生じる誤差を行っているらしい。強制的に LANG=C を指定することで回避できる。 LANG=C sort hoge > sorted_hoge LANG=C sort fuga > sorted_fuga LANG=C join sorted_hoge sorted_fuga > hogefuga すみません勉強不足でした。

awkで最大値・最小値

以下のようにして実装できる。関数の定義と三項演算子の使用がポイント。 echo "6 5 " | awk ' function max(a, b) { return a>b ? a : b } {print max(1, 2)} ' シングルクオートの中は改行しようと ; があろうとなかろうとどうでも良い。

shellで集合演算

シェルで集合演算をやりたかった。でもあまり自信がなかったのでいつもRの %in% で済ませていた。以下のようにしてできるらしい。 論理和 cat a b | sort | uniq 論理積 cat a b | sort | uniq -d 排他的論理和 cat a b | sort | uniq -u 差集合(A-B) (cat a b | sort | uniq -u; cat b) | sort | uniq -d 差集合(B-A) (cat a b | sort | uniq -u; cat a) | sort | uniq -d

私のためのvimrc

" ファイルタイプ別のプラグイン・インデントを有効化 filetype plugin on filetype indent on " 検索後のハイライトをオフ set nohlsearch " バックスペースで以下の文字を削除 set backspace=indent,eol,start set smartindent set smarttab set tabstop=2 softtabstop=2 shiftwidth=2 set expandtab set ignorecase smartcase set incsearch set ruler set title set number relativenumber set scrolloff=1000 set showcmd set showmode " tells us which mode we're in. set showtabline=1 set laststatus=2 " always show set backspace=indent,eol,start set whichwrap=b,s,h,l,<,>,[,] set synmaxcol=200 set tildeop set cursorline set nocursorcolumn set splitbelow splitright set history=255 set nostartofline "don't move with <C-f>, etc. set tags+=codex.tags " haskell set spelllang=en_gb set helplang=en set wildmode=longest,list,full set wildmenu set list set listchars=tab:>-,trail:- set conceallevel=1 set matchpairs=(:),{:},[:] set showmatch set matchtime=2 set foldcolumn=0 " set foldmethod=marker set foldme...

aspera

asperaというソフトがある( https://www-01.ibm.com/software/jp/info/aspera/ )。SRAやERAからのダウンロードはこちらが推奨されているらしい。FTPの100倍早いと。 https://downloads.asperasoft.com/en/downloads/8?list のdirect downloadのリンクでシェルスクリプトがダウンロードされる。実行すると勝手にインストールされる。 使い方は ~/.aspera/connect/bin/ascp \ -i ~/.aspera/connect/etc/asperaweb_id_dsa.openssh \ -QT -l100m \ anonftp@ftpprivate.ncbi.nlm.nih.gov:/1000genomes/ftp/phase3/data/NA18699/sequence_read \ TEST でダウンロードできる。私の環境では100Mb/sでダウンロードできた。