Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Last active August 29, 2015 14:21

compare:

cat raw_expression.txt | head
cat raw_expression.txt | awk -F"\t" '{if(NR==1) $1="NAME"FS$1}1' OFS="\t" | head 

$1 is the first field for each line.
$1="NAME" FS $1 assigns NAME to the first field and seperate by a field seprator (FS), which is a tab.
1 is always TRUE, so awk prints out the rest of the lines.

then, add a second column with a dummy "na":

awk -F"\t" '{$1=$1FS"na"}1' OFS="\t"

How many probes in the file?
echo "$(cat raw_expression.txt| wc -l)-1" | bc
22277

bc is a linux command calculator

How many samples in the file?
cat raw_expression.txt | awk '{print NF;exit}'
14 samples.
after reading the first line and printing out the column number exit awk.

Add two lines in the beginning of the file:

cat raw_expression.txt | \
| awk -F"\t" '{if(NR==1) $1="NAME"FS$1}1' OFS="\t" \
| awk -F"\t" '{$1=$1FS"na"}1' OFS="\t" \
| awk 'BEGIN{print "#1.2""\n"22277"\t"14}1' > raw_experssion.gct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment