I have a script that create a txt file with a lot of information. I want to check if there is a specific text in it, and copy what come after.for example, this is the txt file:blablablaWANTEDTEXT[TEXTTOCOPY]blablabla...where I want to check if WANTEDTEXT is exist and if so, copy what come next in [ and ] aka TEXTTOCOPY.thanks
how to find a text and copy the text after?
search;text
> echo blablablaWANTEDTEXT[TEXTTOCOPY]blablabla... | > awk -v searchtext=WANTEDTEXT '$0 ~ searchtext \\[.*\\] {    strstart=index($0,searchtext [)+length(searchtext)+1;    tmpstr=substr($0,strstart); sub(].*$,,tmpstr); print tmpstr; } 'TEXTTOCOPY