0% found this document useful (0 votes)
27 views

Awk Programming: 1. General 2. Awk With Conditions

This document provides an introduction to awk programming and discusses awk conditions. It outlines basic awk concepts like NR, NF, FS, and OFS. It also provides examples of using simple conditions, for loops, and if loops in awk scripts. Links are included for further reading on awk conditional statements and for loops. An example awk script is given to extract a ratio value from a tab-delimited file and assign it to a variable.

Uploaded by

Binh Vo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Awk Programming: 1. General 2. Awk With Conditions

This document provides an introduction to awk programming and discusses awk conditions. It outlines basic awk concepts like NR, NF, FS, and OFS. It also provides examples of using simple conditions, for loops, and if loops in awk scripts. Links are included for further reading on awk conditional statements and for loops. An example awk script is given to extract a ratio value from a tab-delimited file and assign it to a variable.

Uploaded by

Binh Vo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

awk Programming

1. General
2. awk with conditions
1. General

FS=-F : awk --help


Basic example
NR: number of rows
NF: number of fields
FS: Input field separator (options -F)
OFS: Output field separator Multiple delimiter: awk -F"\t|," (delimiter \t or ,)
Modify from outside variable of bash and awk independent

a=”sold”
Modify from outside
2. Awk with conditions (simple conditions, For loop, If loop)

Example GTF file


https://gist.github.com/decodebiology/1e7cca357e52a181dc25#file-sample-gtf

See excel file


https://www.thegeekstuff.com/2010/02/awk-conditional-statements/
https://linuxhint.com/for_loop_awk_command/
ratio=$(awk -F"\t" 'NR==1 {for (i=1;i<=NF;i++){print i,$i};exit}' bigTable.tsv | grep "087-P11.ratio" | cut -d" " -f1)
echo $ratio

ratio1=$(“command”)
echo $ratio1 (1)

ratio2=”command”
eval ratio2 (2)

(1) = (2)

You might also like