I am having problems with grep and awk. I think it\'s because my input file contains text that looks like code.
The input file contains ID names and looks like this:
This was a nice bash
ish try. The problem was that You always overwrite the result file. Use '>>' instead of >
or move the >
after done
grep -w $line reference.file >> outputfile
or
done > outputfile
But I would prefer Lev's solution as it starts an external process only once.
If You want to solve it in pure bash
, you could try this:
ID=($(outputfile
cat outputfile
Output:
ENSG00000199537 SNORD115-40
ENSG00000207793 MIR432
ENSG00000207447 RNU6-2
Newer bash
supports associative arrays. It can be used to simplify and speed up the search for a key:
declare -A ID
for i in $(