How to read output of sed into a variable

前端 未结 4 1765
野性不改
野性不改 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-14 00:06

    The simplest way is

    logfile="${a/\.txt/\.log}"
    

    If it should be allowed that the filename in $a has more than one occurrence of .txt in it, use the following solution. Its more safe. It only changes the last occurrence of .txt

    logfile="${a%%\.txt}.log"
    

提交回复
热议问题