I want to extract the text after the pattern "List values are here:" that are in quotes in a list. I'm very new to this. Can someone please assist
List values are here: "list1 abc" "list2 test" "end of list"
What I have done:
echo $va| awk '/List values are here:/ {print $1}' var="$va"
You do not need to use awk or sed for this kind of task since you only need to fetch some part of a line. grep is the tool you are looking for.
$ grep -oP '(?<=List values are here: ).*'
EXAMPLE:
$ echo 'List values are here: "list1 abc" "list2 test" "end of list"' | grep -oP '(?<=List values are here: ).*'
"list1 abc" "list2 test" "end of list"
after you can assign the result to a variable or do whatever you want with it.
Explanations:
- -o is to change the default behavior of grep which is outputting the whole line to outputting only the pattern
- -P is to use perl regex
- (?<=List values are here: ).* regex to fetch everything after List values are here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With