How to remove the last character from a bash grep output

后端 未结 14 1583
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 06:29
COMPANY_NAME=`cat file.txt | grep \"company_name\" | cut -d \'=\' -f 2` 

outputs something like this

\"Abc Inc\";

14条回答
  •  盖世英雄少女心
    2020-12-08 06:59

    Using sed, if you don't know what the last character actually is:

    $ grep company_name file.txt | cut -d '=' -f2 | sed 's/.$//'
    "Abc Inc"
    

提交回复
热议问题