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:41] 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 56: Line 56:
  
 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 82: Line 82:
  
 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
awk_for_tabulated_files.1625586066.txt.gz · Last modified: by 156.34.16.174