Bash-Oneliner/params.json

6 lines
27 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-09-05 07:42:28 +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 filename\r\n```\r\n\r\n#####grep only one/first match (e.g. bbo)\r\n\r\n```bash\r\ngrep -m 1 bbo filename\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#####grep variable from variable\r\n```bash\r\n$echo \"$long_str\"|grep -q \"$short_str\"\r\nif [ $? -eq 0 ]; then echo 'found'; fi\r\n```\r\n//grep -q will output 0 if match found\r\n//remember to add space between []!\r\n\r\n#####grep strings between a bracket()\r\n```bash\r\ngrep -oP '\\(\\K[^\\)]+'\r\n```\r\n\r\n#####grep number of characters with known strings in between(e.g. AAEL000001-RA)\r\n```bash\r\ngrep -o -w \"\\w\\{10\\}\\-R\\w\\{1\\}\"\r\n```\r\n// \\w word character [0-9a-zA-Z_] \\W not word character \r\n\r\n\r\n#####a lot examples here\r\nhttp://www.cyberciti.biz/faq/grep-regular-expressions/\r\n\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#####delete last character from end of file\r\n```bash\r\nsed -i '$ s/.$//' filename\r\n```\r\n\r\n#####add string to end of file (e.g. \"]\")\r\n\r\n```bash\r\nsed '$s/$/]/' filename\r\n```\r\n\r\n#####add string to end of each line (e.g. \"}\")\r\n```bash\r\nsed -e 's/$/\\}\\]/' filename\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#####concatenate/combine/join files with a seperator and next line (e.g seperate by \",\")\r\n\r\n```bash\r\nsed -s '$a,' *.json > all.json\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
2016-07-01 11:20:04 +00:00
"note": "Don't delete this file! It's used internally to help with page regeneration."
}