meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
general:computerenvironment:bash [2019/04/24 12:36] – [A non-comprehensive list of bash commands] ruben | general:computerenvironment:bash [2023/04/11 13:17] (current) – felix | ||
---|---|---|---|
Line 4: | Line 4: | ||
You can try the [[http:// | You can try the [[http:// | ||
- | Feel free to complement your notes on the [[media=https:// | + | Feel free to complement your notes on the {{ : |
===== Slightly more advanced bash ===== | ===== Slightly more advanced bash ===== | ||
Line 11: | Line 11: | ||
This command is also considered a programming language on its own. It is particularly useful when you need to process the elements of a table. The basic syntax is as follows: | This command is also considered a programming language on its own. It is particularly useful when you need to process the elements of a table. The basic syntax is as follows: | ||
- | <font 14px/ | + | <code>awk -F " |
- | * use after reading the contents of your table, i.e. after cat file.txt | + | * -F to indicate the delimiter of your table as tabs (default is space). |
- | * indicate the **<font inherit/ | + | * ' |
- | * **<font inherit/ | + | * Text added to the output |
- | * **<font inherit/ | + | * You can also process columns by mathematical operations. For instance, |
- | * You can also process columns by mathematical operations. For instance, print $1+ $2 | + | |
- | <font 16px/ | ||
- | | + | < |
+ | |||
+ | | ||
* Equal == | * Equal == | ||
* Non equal =! | * Non equal =! | ||
* > Greater than | * > Greater than | ||
- | * In this example | + | * ' |
---- | ---- | ||
Line 31: | Line 31: | ||
=== Sort === | === Sort === | ||
- | <font inherit/ | + | <code>sort -g -u file.txt</code> |
- | * -r if you want descending order | + | * -r to sort in descending order |
- | * -g if you want to sort by number | + | * -g to sort by number |
- | * -k sort by a specific column | + | * -k1,1 to sort by a specific column, |
- | + | * -u make values | |
- | ---- | + | * -t ' ' |
- | + | ||
- | === Sort more === | + | |
- | + | ||
- | <font inherit/ | + | |
- | + | ||
- | * -u for unique | + | |
- | * -t to select a delimiter as space (default is tab) | + | |
- | * -k1,1 to apply the unique only for the value of the first column, but still keeping the rest of the row. | + | |
---- | ---- | ||
Line 51: | Line 43: | ||
=== Translate === | === Translate === | ||
- | <font inherit/ | + | <code>tr ' |
* This is a trick if you are working on the complementary strand. | * This is a trick if you are working on the complementary strand. | ||
Line 61: | Line 53: | ||
=== sed (slightly more advanced) === | === sed (slightly more advanced) === | ||
- | <font inherit/ | + | <code>sed -n -e '/ |
+ | |||
+ | * This will find AAA, and keep all the lines in a file until it reaches BBB. Pro tip: use this one to extract a sequence in a multi-line fasta. | ||
+ | * Note that using variables inside a sed command requires double quotation marks " instead of single '. | ||
+ | |||
+ | ===== Working with lists and tables ===== | ||
+ | |||
+ | Play with the following sample files.{{ : | ||
+ | |||
+ | === comm === | ||
+ | |||
+ | To compare contents of both files (in this case, the identifiers of the first column of the two files): | ||
+ | |||
+ | < | ||
+ | |||
+ | * Within each "< | ||
+ | * These should be sorted out | ||
+ | * I use the second part of the command (the sed) to adjust the output to have the correct number of columns | ||
+ | |||
+ | < | ||
+ | |||
+ | * Output: | ||
+ | * First column: identifiers exclusive of the table in input 1 | ||
+ | * Second column: identifiers exclusive of the table in input 2 | ||
+ | * Third column: identifiers present in both tables | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | === join === | ||
+ | |||
+ | Join two tables based on a column in common. | ||
+ | |||
+ | < | ||
+ | |||
+ | * Input within the "< | ||
+ | * I highly recommend using only the first column with the identifiers to join. | ||
+ | * If one of the tables has repeated identifiers, | ||
+ | * The standard output will display only lines with columns in common. We can add option -a1 or -a2 to also include the entries of one of the tables, with no joined values from other. Do not use both. | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
- | * <font inherit/ | ||
- | * <font inherit/ | ||