I've been trying all the morning thinking how to do what I want to do but... I am starting to feel desperate!
I have an array of rows and columns in a .txt file. So I want to create a script that gives to me this information:
If I type it to the terminal (script.sh 1 2 3), it should give me columns 1 to 3 from the .txt file.
If I type it to the terminal (script.sh), it should give me column 5 to the last column.
If I type it to the terminal (script.sh 1 2 3 -g insulin), it should give me columns 1 to 3 of the rows that contain the word "insulin". The -g here means "gene", so the aim is to look for that gene.
I've written a code that gives me the columns I want or all the columns if I don't introduce any variable, but I can't go ahead with the -g and gene variables... Do you have any idea?
Here's my code:
#!/bin/bash
var="$(echo $@ | tr " " ",")"
if [ $# = 0 ]; then
awk '{for (x=5; x<=NF; x++) {printf "%s ", $x } printf "\n" }' affy.txt
else
cat affy.txt | cut -d" " -f$var
fi
Thank you!