Case-insensitive search and replace with sed

前端 未结 8 1905
暗喜
暗喜 2020-11-28 08:51

I\'m trying to use SED to extract text from a log file. I can do a search-and-replace without too much trouble:

sed \'s/foo/bar/\' mylog.txt
<
8条回答
  •  北海茫月
    2020-11-28 09:47

    If you are doing pattern matching first, e.g.,

    /pattern/s/xx/yy/g
    

    then you want to put the I after the pattern:

    /pattern/Is/xx/yy/g
    

    Example:

    echo Fred | sed '/fred/Is//willma/g'
    

    returns willma; without the I, it returns the string untouched (Fred).

提交回复
热议问题