User Tools

Site Tools


unix_shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
unix_shell [2021/11/08 19:12] 38.20.199.40unix_shell [2022/06/23 10:21] (current) 134.190.232.106
Line 1: Line 1:
-upcoming+The commonly used scripts collected from previous Github page and course materials.
  
-Here's a list of commands to retrieve deleted text in vi:+1.How to set up timer for specific script run? 
 + 
 +<code> 
 +#!/bin/bash 
 +# Twosday.sh 
 + 
 +while true; 
 +do 
 +    DATE=`date | cut -d' ' -f4` 
 +    #echo $DATE 
 +    if [[ $DATE == "22:22:22" ]] 
 +    then 
 +            echo "this is a test program" >> xyz.log 
 +            qrsh 
 +            sleep 1s 
 +    fi 
 +done 
 +</code> 
 + 
 +<code> 
 +#stopwatch 
 +#https://superuser.com/questions/611538/is-there-a-way-to-display-a-countdown-or-stopwatch-timer-in-a-terminal 
 +while true; do echo -ne "`date`\r"; done 
 +#nanoseconds: 
 +while true; do echo -ne "`date +%H:%M:%S:%N`\r"; done 
 +</code> 
 + 
 + 
 +2.Here's a list of commands to retrieve deleted text in vi:
  
 <code> <code>
Line 62: Line 90:
  
  
-<Last updated by Xi Zhang on Oct 6th,2021>+ 
 +<code> 
 +#Remove duplicates in fasta file based on ID 
 + 
 +https://www.biostars.org/p/321641/ 
 + 
 +awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;next;} {printf("%s",$0);} END {printf("\n");}' 1.fa|sort -t $'\t' -k1,1 -u |tr "\t" "\n" 
 + 
 +https://www.biostars.org/p/143617/ 
 + 
 +awk '/^>/{f=!d[$1];d[$1]=1}f'  
 +</code> 
 + 
 +<code> 
 +https://github.com/brentp/pyfasta 
 +# To install python2 version 
 +pip install pyfasta 
 +# To install python3 version 
 +pip3 install pyfasta 
 + 
 +#split a fasta file into 6 new files of relatively even size: 
 +pyfasta split -n 6 original.fasta 
 +</code> 
 + 
 +Rename file name with the one user wanted https://linuxgazette.net/18/bash.html 
 +https://unix.stackexchange.com/questions/580506/renaming-multiple-files-using-a-loop 
 +<code> 
 + 
 +for i in *; do -- mv "$i" "${i/%.fasta/.fa}"; done 
 +for f in *; do mv "$f" "${f#*_}";done 
 + 
 +for i in chr* 
 +do 
 +  mv -- "$i" "${i/%.fasta/.fa}" 
 +done 
 +or 
 + 
 +for i in chr* 
 +do 
 +  NEWNAME="${i/%.fasta/.fa}" 
 +  mv -- "$i" "$NEWNAME" 
 +done 
 +The "%{var/%pat/replacement}" looks for pat only at the end of the variable and replaces it with replacement. 
 +</code> 
 + 
 +<code> 
 +Usage: 
 +    rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr 
 +    [ files ] 
 +</code> 
 + 
 + 
 +How to use sort in linux, especially ignore the header to sort special col? 
 +<code> 
 +(head -n 1 all.txt && tail -n +2 all.txt| sort -n -r -k2) > 123.txt 
 + 
 +# sort -n 
 +#sort -r 
 +#sort -k 
 +https://shapeshed.com/unix-sort/; https://stackoverflow.com/questions/14562423/is-there-a-way-to-ignore-header-lines-in-a-unix-sort 
 +</code> 
 + 
 +<Last updated by Xi Zhang on Oct 6th,2021> <June 23th,2022>
unix_shell.1636413168.txt.gz · Last modified: by 38.20.199.40