Update README.md

This commit is contained in:
onceupon 2017-03-29 17:54:35 +08:00 committed by GitHub
parent 743db35c52
commit 71493924ad

165
README.md
View File

@ -117,7 +117,7 @@ grep $'\t'
$echo "$long_str"|grep -q "$short_str" $echo "$long_str"|grep -q "$short_str"
if [ $? -eq 0 ]; then echo 'found'; fi if [ $? -eq 0 ]; then echo 'found'; fi
``` ```
//grep -q will output 0 if match found //grep -q will output 0 if match found
//remember to add space between []! //remember to add space between []!
##### grep strings between a bracket() ##### grep strings between a bracket()
@ -128,7 +128,7 @@ grep -oP '\(\K[^\)]+'
##### grep number of characters with known strings in between(e.g. AAEL000001-RA) ##### grep number of characters with known strings in between(e.g. AAEL000001-RA)
```bash ```bash
grep -o -w "\w\{10\}\-R\w\{1\}" grep -o -w "\w\{10\}\-R\w\{1\}"
``` ```
// \w word character [0-9a-zA-Z_] \W not word character // \w word character [0-9a-zA-Z_] \W not word character
@ -152,12 +152,12 @@ sed "/bbo/d" filename
sed -i "/bbo/d" filename sed -i "/bbo/d" filename
``` ```
##### when using variable (e.g. $i), use double quotes " " ##### when using variable (e.g. $i), use double quotes " "
e.g. add >$i to the first line (to make a FASTA file) e.g. add >$i to the first line (to make a FASTA file)
```bash ```bash
sed "1i >$i" sed "1i >$i"
``` ```
//notice the double quotes! in other examples, you can use a single quote, but here, no way! //notice the double quotes! in other examples, you can use a single quote, but here, no way!
//'1i' means insert to first line //'1i' means insert to first line
@ -270,8 +270,8 @@ sed 's/,$//g'
```bash ```bash
sed "s/$/\t$i/" sed "s/$/\t$i/"
``` ```
//$i is the valuable you want to add //$i is the valuable you want to add
e.g. add the filename to every last column of the file e.g. add the filename to every last column of the file
```bash ```bash
for i in $(ls);do sed -i "s/$/\t$i/" $i;done for i in $(ls);do sed -i "s/$/\t$i/" $i;done
@ -395,58 +395,48 @@ cat file| awk -F '\t' 'BEGIN {SUM=0}{SUM+=$3-$2}END{print SUM}'
``` ```
##### usage and meaning of NR and FNR ##### usage and meaning of NR and FNR
e.g. e.g.
fileA: fileA:
a a
b b
c c
fileB: fileB:
d d
e e
```bash ```bash
awk 'print FILENAME, NR,FNR,$0}' fileA fileB awk 'print FILENAME, NR,FNR,$0}' fileA fileB
``` ```
fileA 1 1 a fileA 1 1 a
fileA 2 2 b fileA 2 2 b
fileA 3 3 c fileA 3 3 c
fileB 4 1 d fileB 4 1 d
fileB 5 2 e fileB 5 2 e
##### and gate ##### and gate
e.g. e.g.
fileA: fileA:
1 0 1 0
2 1
3 1
4 0
2 1 fileB:
1 0
3 1 2 1
3 0
4 0 4 1
fileB:
1 0
2 1
3 0
4 1
```bash ```bash
awk -v OFS='\t' 'NR=FNR{a[$1]=$2;next} NF {print $1,((a[$1]=$2)? $2:"0")}' fileA fileB awk -v OFS='\t' 'NR=FNR{a[$1]=$2;next} NF {print $1,((a[$1]=$2)? $2:"0")}' fileA fileB
``` ```
1 0 1 0
2 1
2 1 3 0
4 0
3 0
4 0
##### round all numbers of file (e.g. 2 significant figure) ##### round all numbers of file (e.g. 2 significant figure)
@ -466,16 +456,13 @@ awk '{printf("%s\t%s\n",NR,$0)}'
``` ```
##### break combine column data into rows ##### break combine column data into rows
e.g. e.g.
seperate seperate
David cat,dog David cat,dog
into
into David cat
David dog
David cat
David dog
detail here: http://stackoverflow.com/questions/33408762/bash-turning-single-comma-separated-column-into-multi-line-string detail here: http://stackoverflow.com/questions/33408762/bash-turning-single-comma-separated-column-into-multi-line-string
```bash ```bash
@ -521,7 +508,7 @@ xargs -d\t
echo 1 2 3 4 5 6| xargs -n 3 echo 1 2 3 4 5 6| xargs -n 3
``` ```
//1 2 3 //1 2 3
4 5 6 4 5 6
@ -537,7 +524,7 @@ echo a b c |xargs -p -n 3
xargs -t abcd xargs -t abcd
``` ```
///bin/echo abcd ///bin/echo abcd
//abcd //abcd
@ -593,7 +580,7 @@ time echo {1..5} |xargs -n1 sleep
find /dir/to/A -type f -name "*.py" -print 0| xargs -0 -r -I file cp -v -p file --target-directory=/path/to/B find /dir/to/A -type f -name "*.py" -print 0| xargs -0 -r -I file cp -v -p file --target-directory=/path/to/B
``` ```
//v: verbose| //v: verbose|
//p: keep detail (e.g. owner) //p: keep detail (e.g. owner)
@ -744,23 +731,15 @@ for i in $(ls); do echo file $i;done
```bash ```bash
wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com
``` ```
//-r: recursive and download all links on page //-r: recursive and download all links on page
//-l1: only one level link
//-l1: only one level link //-H: span host, visit other hosts
//-t1: numbers of retries
//-H: span host, visit other hosts //-nd: don't make new directories, download to here
//-N: turn on timestamp
//-t1: numbers of retries //-nd: no parent
//-A: type (seperate by ,)
//-nd: don't make new directories, download to here //-e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.com
//-N: turn on timestamp
//-nd: no parent
//-A: type (seperate by ,)
//-e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.com
@ -993,7 +972,7 @@ or
##### extract .xf ##### extract .xf
1.unxz filename.tar.xz 1.unxz filename.tar.xz
2.tar -xf filename.tar 2.tar -xf filename.tar
##### install python package ##### install python package
@ -1082,7 +1061,7 @@ rsync -av --update directory directory.bak
```bash ```bash
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat} mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat}
``` ```
//-p: make parent directory //-p: make parent directory
//this will create project/doc/html/; project/doc/info; project/lib/ext ,etc //this will create project/doc/html/; project/doc/info; project/lib/ext ,etc
@ -1294,15 +1273,11 @@ head -c 50 file
``` ```
##### group/combine rows into one row ##### group/combine rows into one row
e.g. e.g.
AAAA
AAAA BBBB
CCCC
BBBB DDDD
CCCC
DDDD
```bash ```bash
cat filename|paste - - cat filename|paste - -
--> -->
@ -1589,7 +1564,7 @@ getent database_name
```bash ```bash
getent passwd getent passwd
``` ```
//list all user account (all local and LDAP) //list all user account (all local and LDAP)
(e.g. fetch list of grop accounts) (e.g. fetch list of grop accounts)
```bash ```bash
@ -1735,7 +1710,7 @@ nmap -sT -O localhost
nproc --all nproc --all
``` ```
##### check status of each core ##### check status of each core
1. top 1. top
2. press '1' 2. press '1'
##### show jobs and PID ##### show jobs and PID
@ -1770,10 +1745,10 @@ ssh -X user_name@ip_address
``` ```
or setting through xhost or setting through xhost
--> Install the following for Centos: --> Install the following for Centos:
xorg-x11-xauth xorg-x11-xauth
xorg-x11-fonts-* xorg-x11-fonts-*
xorg-x11-utils xorg-x11-utils
##### kill all process of a user ##### kill all process of a user
@ -1784,16 +1759,16 @@ pkill -U user_name
-->you might have to install the following: -->you might have to install the following:
apt-get install libglib2.0-bin; apt-get install libglib2.0-bin;
yum install dconf dconf-editor; yum install dconf dconf-editor;
yum install dbus dbus-x11; yum install dbus dbus-x11;
-->Check list -->Check list
```bash ```bash
gsettings list-recursively gsettings list-recursively
``` ```
-->Change setting -->Change setting
e.g. e.g.
```bash ```bash
gsettings set org.gnome.gedit.preferences.editor highlight-current-line true gsettings set org.gnome.gedit.preferences.editor highlight-current-line true