Return a regex match in a Bash script, instead of replacing it

前端 未结 9 791
面向向阳花
面向向阳花 2021-01-31 04:30

I just want to match some text in a Bash script. I\'ve tried using sed but I can\'t seem to make it just output the match instead of replacing it with something.



        
9条回答
  •  面向向阳花
    2021-01-31 04:34

    using just the bash shell

    declare -a array
    i=0
    while read -r line
    do
            case "$line" in
                *TestT*String* )
                while true
                do
                    line=${line#*TestT}
                    array[$i]=${line%%String*}
                    line=${line#*String*}
                    i=$((i+1))
                    case "$line" in
                        *TestT*String* ) continue;;
                        *) break;;
                    esac
                done
                esac
    done <"file"
    echo ${array[@]}
    

提交回复
热议问题