Using sed to delete a case insensitive matched line

后端 未结 2 693
执念已碎
执念已碎 2020-12-30 19:39

How do I match a case insensitive regex and delete it at the same time

I read that to get case insensitive matches, use the flag \"i\"

sed -e \"/patt         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 20:22

    you can use (g)awk as well.

    # print case insensitive
    awk 'BEGIN{IGNORECASE=1}/pattern/{print}' file
    
    # replace with case insensitive
    awk 'BEGIN{IGNORECASE=1}/pattern/{gsub(/pattern/,"replacement")}1' file
    

    OR just with the shell(bash)

    #!/bin/bash
    shopt -s nocasematch
    while read -r line
    do
        case "$line" in
            *pattern* ) echo $line;
        esac
    done <"file"
    

提交回复
热议问题