Bash-Oneliner/params.json

6 lines
24 KiB
JSON
Raw Normal View History

2016-07-01 11:20:04 +00:00
{
"name": "Bash-oneliner",
"tagline": "Bash Oneliner learning station. This blog will focus on bash commands for parsing biological data, which are tsv files(tab-separated values); some of the commands are for Ubuntu system maintaining. I apologize that there won't be any citation of the code, but they are probably from dear Google and Stackoverflow. Not all the code here are oneliner (if the ';' counts..). English and bash are not my first language, so... correct me anytime, tks!!",
2016-07-01 11:22:39 +00:00
"body": "##Handy Bash oneliner commands for tsv file editing\r\n\r\n- [Grep](#grep)\r\n- [Sed](#sed)\r\n- [Awk](#awk)\r\n- [Xargs](#xargs)\r\n- [Find](#find)\r\n- [Loops](#loops)\r\n- [Download](#download)\r\n- [Random](#random)\r\n- [Others](#others)\r\n- [System](#system)\r\n\r\n##Grep\r\n#####extract text bewteen words (e.g. w1,w2)\r\n \r\n```bash\r\ngrep -o -P '(?<=w1).*(?=w2)'\r\n```\r\n\r\n#####grep lines without word (e.g. bbo)\r\n \r\n```bash\r\ngrep -v bbo\r\n```\r\n\r\n#####grep and count (e.g. bbo)\r\n \r\n```bash\r\ngrep -c bbo filename\r\n```\r\n\r\n#####insensitive grep (e.g. bbo/BBO/Bbo)\r\n \r\n```bash\r\ngrep -i \"bbo\" filename \r\n```\r\n\r\n#####count occurrence (e.g. three times a line count three times)\r\n \r\n```bash\r\ngrep -o bbo filename \r\n```\r\n\r\n#####COLOR the match (e.g. bbo)!\r\n \r\n```bash\r\ngrep --color bbo filename \r\n```\r\n\r\n#####grep search all files in a directory(e.g. bbo)\r\n \r\n```bash\r\ngrep -R bbo /path/to/directory \r\n```\r\n\r\nor\r\n \r\n```bash\r\ngrep -r bbo /path/to/directory \r\n```\r\n#####search all files in directory, only output file names with matches(e.g. bbo)\r\n \r\n```bash\r\ngrep -Rh bbo /path/to/directory \r\n```\r\nor\r\n```bash \r\ngrep -rh bbo /path/to/directory \r\n```\r\n\r\n#####grep OR (e.g. A or B or C or D)\r\n \r\n```\r\ngrep 'A\\|B\\|C\\|D' \r\n```\r\n\r\n#####grep AND (e.g. A and B)\r\n \r\n```bash\r\ngrep 'A.*B' \r\n```\r\n\r\n#####grep all content of a fileA from fileB\r\n \r\n```bash\r\ngrep -f fileA fileB \r\n```\r\n\r\n#####grep a tab\r\n \r\n```bash\r\ngrep $'\\t' \r\n```\r\n\r\n##Sed\r\n[[back to top](#handy-bash-oneliner-commands-for-tsv-file-editing)]\r\n\r\n#####remove lines with word (e.g. bbo)\r\n \r\n```bash\r\nsed \"/bbo/d\" filename\r\n```\r\n\r\n#####edit infile (edit and save)\r\n \r\n```bash\r\nsed -i \"/bbo/d\" filename\r\n```\r\n#####when using variable (e.g. $i), use double quotes \" \"\r\ne.g. add >$i to the first line (to make a FASTA file)\r\n \r\n```bash\r\nsed \"1i >$i\" \r\n```\r\n//notice the double quotes! in other examples, you can use a single quote, but here, no way! \r\n//'1i' means insert to first line\r\n\r\n\r\n#####delete empty lines\r\n \r\n```bash\r\nsed '/^\\s*$/d' \r\n``` \r\nor\r\n \r\n```bash\r\nsed 's/^$/d' \r\n```\r\n#####delete last line\r\n \r\n```bash\r\nsed '$d' \r\n```\r\n\r\n#####add \\n every nth character (e.g. every 4th character)\r\n \r\n```bash\r\nsed 's/.\\{4\\}/&\\n/g' \r\n```\r\n\r\n#####substitution (e.g. replace A by B)\r\n \r\n```bash\r\nsed 's/A/B/g' filename \r\n```\r\n#####select lines start with string (e.g. bbo)\r\n \r\n```bash\r\nsed -n '/^@S/p' \r\n```\r\n#####delete lines with string (e.g. bbo)\r\n \r\n```bash\r\nsed '/bbo/d' filename \r\n```\r\n#####print every nth lines\r\n \r\n```bash\r\nsed -n '0~3p' filename\r\n```\r\n//catch 0: start; 3: step\r\n\r\n\r\n#####print every odd # lines\r\n \r\n```bash\r\nsed -n '1~2p' \r\n```\r\n#####print every third line including the first line\r\n \r\n```bash\r\nsed -n '1p;0~3p' \r\n```\r\n#####remove leading whitespace and tabs\r\n \r\n```bash\r\nsed -e 's/^[ \\t]*//'\r\n```\r\n//notice a whitespace before '\\t'!!\r\n\r\n\r\n#####remove only leading whitespace\r\n \r\n```bash\r\nsed 's/ *//'\r\n```\r\n//notice a whitespace before '*'!!\r\n\r\n\r\n#####remove ending commas\r\n \r\n```bash\r\nsed 's/,$//g' \r\n```\r\n#####add a column to the end\r\n \r\n```bash\r\nsed \"s/$/\\t$i/\"\r\n```\r\n//$i is the valuable you want to add\r\ne.g. add the filename to every last column of the file\r\n \r\n```bash\r\nfor i in $(ls);do sed -i \"s/$/\\t$i/\" $i;done\r\n```\r\n\r\n#####remove newline\\ nextline\r\n \r\n```bash\r\nsed ':a;N;$!ba;s/\\n//g'\r\n```\r\n\r\n#####print a number of lines (e.g. line 10th to line 33 rd)\r\n \r\n```bash\r\nsed -n '10,33p' <filename\r\n```\r\n\r\n\r\n#Awk\r\n[[back to top](#handy-bash-oneliner-commands-for-tsv-file-editing)]\r\n\r\n#####set tab as field separator\r\n \r\n```bash\r\nawk -F $'\\t' \
2016-07-01 11:20:04 +00:00
"note": "Don't delete this file! It's used internally to help with page regeneration."
}