2023-02-13
''
{print}
to indicate lines or columns you want to see$N
(replace N with the number),
:
{print $N,$X}
$0
# Print second column of the file blastp_results.txt
awk '{print $2}' blastp_results.txt
# Print second and third columns of the file blastp_results.txt
awk '{print $2,$3}' blastp_results.txt
Inside the ''
add the word your searching for in //
# Print lines containing "#" in blastp_results.txt
awk '/#/ {print}' blastp_results.txt
# Print lines NOT containing "#" in blastp_results.txt
awk '!/#/ {print}' blastp_results.txt
$0
, you print the whole lineawk 'NR > 1 {print}' blastp_results.txt
awk 'NR == 1 {print $1} NR > 1 {print $2}' blastp_results.txt
awk '{print $NF}' blastp_results.txt
Note the these can be specified by adding BEGIN {}
:
awk 'BEGIN {FS=","} {print $2}' blastp_results.csv
''
-F","
or --field-separator=","
are the sameawk 'BEGIN {OFS=","} {print $1,$2,$3}' blastp_results.txt
Note the these can be specified by adding BEGIN {}
:
awk 'BEGIN {RS=">"} {print $1}' myFasta.fasta
awk 'BEGIN {ORS=">"} {print $1}' myFasta.txt
awk 'BEGIN {FS = "\n"; RS=">"}\
{print $1, length($2)}' ~/blastClass/myFasta.fasta
awk 'BEGIN {FS = "\n"; RS=">";\
OFS="\t"; ORS="\n"}\
{print $1,$2}' ~/blastClass/myFasta.fasta
'*'
awk 'BEGIN {FS = "\n"; RS=">"}\
{newSeq=gensub(/N/, "*", $2); print $1, newSeq}' ~/blastClass/myFasta.fasta
{}
come after if
and inside ()
OR they go outside the {}
# Print line if column 3 has a value greater than 80
awk '{if ($3 > 80) print}' ~/blastClass/myFasta.fasta
{}
# Print line if column 3 has a value greater than 80
awk '$3 > 80 {print}' ~/blastClass/myFasta.fasta
&&
# Print line if column 3 has a value greater than 80 AND column 4 has a value greater than 150
awk '{if ($3 > 80 && $4 > 150) print}' ~/blastClass/myFasta.fasta
# This also gives the same result
awk '$3 > 80 && $4 > 150 {print}' ~/blastClass/myFasta.fasta
||
# Print line if column 3 has a value greater than 80 OR column 4 has a value greater than 150
awk '{if ($3 > 80 || $4 > 150) print}' ~/blastClass/myFasta.fasta
awk '$3 > 80 || $4 > 150 { print }' ~/blastClass/myFasta.fasta