Need help matching a mattern using grep/egrep in bash scripting

后端 未结 3 1383
面向向阳花
面向向阳花 2021-01-22 21:58

I am trying to match all characters of given string but those characters should match in the order as given to the bash script.

while [[ $# -gt 0 ]]; do
  case $         


        
3条回答
  •  遇见更好的自我
    2021-01-22 22:20

    Change this:

    arg=$2
    egrep "*[$arg]*" words.txt
    

    to this:

    arg=$(sed 's/./.*[&]/g' <<< "$2")
    grep "$arg" words.txt
    

    If that's not all you need then edit your question to clarify your requirements and provide more truly representative sample input/output.

提交回复
热议问题