extract regexp result from string and write it to a variable

前端 未结 5 1449
星月不相逢
星月不相逢 2021-01-24 19:05

I\'m trying to write a shell script that searches in a file specified as argument $1 for a regex and writes the found subpattern into a variable I can then use.

let\'s s

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 19:35

    You could try something along the lines of

    value=`grep '^set output' $x | cut -d' ' -f 3`
    

    (Note that you will retain the quotes in $value

提交回复
热议问题