Issue
My sentence is
abcde^10=fgi^11=jkl^12=lmn
The sequence can be jumbled also for eg.
abcde^11=jkl^12=lmn^10=fgi
12=lmn^11=jkl^10=fgi^abcde
I want to print lmn
.
I have gotten till thus far:
~$ echo abcde^10=fgi^11=jkl^12=lmn|grep -o '\^12=[^)]*\^' -> this doesnt print anything
~$ echo abcde^11=jkl^12=lmn^10=fgi|grep -o '\^12=[^)]*\^' -> this prints ^12=lmn^
Solution
With GNU awk for multi-char RS:
$ echo 'abcde^10=fgi^11=jkl^12=lmn' | awk -v RS='[\n^]' -F'=' '$1==12{print $2}'
lmn
$ echo '12=lmn^11=jkl^10=fgi^abcde' | awk -v RS='[\n^]' -F'=' '$1==12{print $2}'
lmn
or using any awk:
$ echo 'abcde^10=fgi^11=jkl^12=lmn' | awk -v RS='^' -F'[=\n]' '$1==12{print $2}'
lmn
$ echo 'abcde^10=fgi^11=jkl^12=lmn' | awk -v RS='^' -F'[=\n]' '$1==12{print $2}'
lmn
Answered By - Ed Morton Answer Checked By - David Goodson (WPSolving Volunteer)