User Tools

Site Tools


awk_for_tabulated_files

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
awk_for_tabulated_files [2021/07/06 12:37] 156.34.16.174awk_for_tabulated_files [2021/07/06 12:42] (current) 156.34.16.174
Line 1: Line 1:
-The command awk can be really useful to edit or parse tabulated files (for example: blast output in columns separated by a tabulation = -outfmt 6; or gff files).+The command awk can be really useful to edit or parse tabulated files (for example: blast outputs in columns separated by a tabulation = -outfmt 6; or gff files).
  
 By default, awk scans a file line by line, whereby a line is ending by a carriage return (\n) and further split the line into fields, by default separated by a tabulation "\t" although other field separators can be defined. By default, awk scans a file line by line, whereby a line is ending by a carriage return (\n) and further split the line into fields, by default separated by a tabulation "\t" although other field separators can be defined.
Line 19: Line 19:
  
  
-How to invert 2 columns (fields)+How to invert 2 columns (fields) \\
 ex: Inverting the query (column 1) and the target (column 2) ex: Inverting the query (column 1) and the target (column 2)
 <code> <code>
Line 34: Line 34:
  
  
-How to use the **if** statement+How to use the **if** statement \\
 ex 1: printing a line if the name of the query (first column) contains "g29" ex 1: printing a line if the name of the query (first column) contains "g29"
 <code> <code>
Line 55: Line 55:
 </code> </code>
  
-How to use the **if** statement with 2 conditions +How to use the **if** statement with 2 conditions \\ 
-printing a line if the name of the query contains "g29" AND if the the hit in the target sequence (column 9) is smaller than 499000+ex: printing a line if the name of the query contains "g29" AND if the the hit in the target sequence (column 9) is smaller than 499000
 <code> <code>
 $user awk -F "\t" '{if (($9 < 499000) && ($1 ~ /g29/)) print}' blast.output $user awk -F "\t" '{if (($9 < 499000) && ($1 ~ /g29/)) print}' blast.output
Line 67: Line 67:
  
  
-printing a line if the name of the query contains "g29" OR if the the hit in the target sequence (column 9) is smaller than 499000+ex: printing a line if the name of the query contains "g29" OR if the the hit in the target sequence (column 9) is smaller than 499000
 <code> <code>
 user$ awk -F "\t" '{if (($9 < 499000) || ($1 ~ /g29/)) print}' blast.output user$ awk -F "\t" '{if (($9 < 499000) || ($1 ~ /g29/)) print}' blast.output
Line 81: Line 81:
  
  
-How to use the if and else statments +How to use the if and else statments \\ 
-printing the first column of a line if the query (first column) contains "g29", else print the full line+ex: printing the first column of a line if the query (first column) contains "g29", else print the full line
 <code> <code>
 user$ awk -F "\t" '{if ($1 ~ /g29/) print $1; else print}' blast.output user$ awk -F "\t" '{if ($1 ~ /g29/) print $1; else print}' blast.output
Line 94: Line 94:
 </code> </code>
  
-How to make numeric operations on certain fields+How to make numeric operations on certain fields \\
 ex 1: printing the column 2, the column 10 and the column 10 -100 ex 1: printing the column 2, the column 10 and the column 10 -100
 <code> <code>
awk_for_tabulated_files.1625585874.txt.gz · Last modified: by 156.34.16.174