Command substitution within sed expression

前端 未结 4 1064
抹茶落季
抹茶落季 2020-12-22 02:49

I\'m having little problem with bash/sed. I need to be able to use command substitution within sed expression. I have two big text files:

  • first is logfile.t

4条回答
  •  萌比男神i
    2020-12-22 03:01

    Just to let people looking for solution with bare shell and sed. Not perfect but working:

    cat logfile.txt | while read line ; do id=$(echo -E "$line" | 
        grep "ERRORID:0x[0-9a-f]*" | grep -o "0x[0-9a-f]*" ) ; 
        if [ ! -z "$id" ] ; then echo -E "$line" | sed "s/$id/$(grep $id errors.txt | 
        grep -o '^[A-Z_]*' )/g" ;else echo -E "$line" ; fi ; done
    

    If you see some fixing options then please share.

提交回复
热议问题