How do I extract text in between strings first instance only.
Source:
test66="keyword1"y67h6y7 test66="keyword2"hj67h67j
test66="keyword3"f54fd543f456
output:
keyword1
How do I extract text in between strings first instance only.
Source:
test66="keyword1"y67h6y7 test66="keyword2"hj67h67j
test66="keyword3"f54fd543f456
output:
keyword1
sed -n '/test66="\(.*\)"/ {s//\1/p; q}' source.txt
Inspired by: https://stackoverflow.com/a/17086464/4323
awk way
Works for your updated requirements
awk '{x=match($0,/test66="([^"]+)"/,a)}x{print a[1];exit}' file
sed way
sed -n '/test66="\([^"]\+\)".*/{s//\1/p;q}' file
They both do pretty much the exact same thing.
1.Search for string
2.Store value inbetween quotes.
3.Print that value
4.Quit
This might work for you (GNU sed):
sed -r '/test66="/{s//\n/;s/^[^\n]*\n([^"]*)".*/\1/;q}' file
Replace the required pattern with a marker i.e. \n
and remove strings either side of the marker, print and quit.