Mercurial > repos > saskia-hiltemann > file_manipulation
comparison chrprefix.sh @ 0:e77c9484b2d0 draft default tip
Uploaded
author | saskia-hiltemann |
---|---|
date | Thu, 22 Oct 2015 09:18:30 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e77c9484b2d0 |
---|---|
1 #!/bin/bash | |
2 | |
3 inputfile=$1 | |
4 col=$2 | |
5 addremove=$3 | |
6 outputfile=$4 | |
7 | |
8 echo "args: $@" | |
9 echo "inputfile: $inputfile" | |
10 echo "column: $column" | |
11 echo "addremove: $addremove" | |
12 echo "outputfile: $outputfile" | |
13 | |
14 #get column number | |
15 column=`expr match "$col" '\([0-9]*\)'` | |
16 echo "colnumber: $column" | |
17 | |
18 if [ $addremove == "add" ] | |
19 then | |
20 echo "adding prefix to column $column" | |
21 awk 'BEGIN{ | |
22 FS="\t" | |
23 OFS="\t" | |
24 c="'"$column"'" | |
25 }{ | |
26 if (index($0,"#")!=1){ | |
27 $c="chr"$c | |
28 } | |
29 print $0 | |
30 | |
31 }END{}' $inputfile > $outputfile | |
32 | |
33 else #remove prefix | |
34 echo "removing prefix from column $column" | |
35 awk 'BEGIN{ | |
36 FS="\t" | |
37 OFS="\t" | |
38 c="'"$column"'" | |
39 }{ | |
40 if (FNR>1 && index($0,"#")!=1){ | |
41 $c=substr($c,4) | |
42 } | |
43 print $0 | |
44 | |
45 }END{}' $inputfile > $outputfile | |
46 fi | |
47 | |
48 echo "inputfile: " | |
49 head -5 $inputfile | |
50 | |
51 echo "outputfile: " | |
52 head -5 $outputfile |