or just
awk '($4=="geneName")' *.bed > output
Hi,
I am a newbie with scripting so I can't find an easy solution to this question by myself and I'd like to ask for some help.
I have a long list of BED files, and for each file I want to scan them row by row and if the content of a given column contains some text I am looking for (say, for example, gene name "A") I want that full row to be copied into a new, separate bed file.
I'm looking fwd to hearing your suggestions,
thanks in advance!
If Input file contains gene name in fourth column, then it will print only that line
cat input.bed | awk 'BEGIN {OFS="\t"} { if ($4 == "geneName") { print $0 }}' > outputFile
If you have many bed files and want to loop
for name in $(ls *bed)
do
cat $name | awk 'BEGIN {OFS="\t"} { if ($4 == "geneName") { print $0 }}' >> outputFile
done
or just
awk '($4=="geneName")' *.bed > output
Think grep is the simplest answer here:
grep $geneName $inputFile >> $outputFile
Or for more than 1 gene per row:
grep -E '$geneName1|geneName2' $inputFile >> $outputFile
Log in to answer this question.
Thank you so much guys!
g.
Great, thank again to you all guys!
g.