How to read output of sed into a variable

前端 未结 4 1770
野性不改
野性不改 2020-12-13 23:28

I have variable which has value \"abcd.txt\".

I want to store everything before the \".txt\" in a second variable, replacing the \".t

4条回答
  •  一个人的身影
    2020-12-13 23:56

    You can use command substitution as:

    new_filename=$(echo "$a" | sed 's/.txt/.log/')
    

    or the less recommended backtick way:

    new_filename=`echo "$a" | sed 's/.txt/.log/'`
    

提交回复
热议问题