例如:
set_false_path -from [sdhjasdjhfvsdhf] -through [fsdfvhbdf] -through [sakjvhbdskfhvbdf jbhshbv sdjkvb]
我只想 grep 从第二行到第二行。
答案1
Expression='set_false_path -from [sdhjasdjhfvsdhf] -through [fsdfvhbdf] -through [sakjvhbdskfhvbdf jbhshbv sdjkvb]'
printf '%s' "$Expression" | grep -o -e '-through \[[^]]*\]' | sed -ne '2p'
输出:
-through [sakjvhbdskfhvbdf jbhshbv sdjkvb]