Matching text using grep or awk

前端 未结 3 1554
轮回少年
轮回少年 2021-01-06 10:45

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:

3条回答
  •  隐瞒了意图╮
    2021-01-06 11:19

    This was a nice bashish 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 $(

提交回复
热议问题