2

My inputs are something like:

["https://www.tesing.com/watch/80239279"],
["https://www.testing.com/watch/80240715?source=35"],
["https://www.testing.com/watch/80242619?trackId=254015180&tctx=0%2C0%2Ce336905e-6b5c-4a93-ad18-57ae35b6eb08-583558810%2C29fea9da-2bf8-43b0-b26a-2da637154825_96118138X20XX1560732016031%2C29fea9da-2bf8-43b0-b26a-2da637154825_ROOT"],
["https://www.testing.com/watch/80242619?tctx=1%252C0%252C%252C%252C"],

so I want extract only parameters (eg: trackId,SourceId)

my regex is /[\?\\&]{1,2}\w+=/.

file.awk

BEGIN {}
{
    match($0, /[\?\\&]{1,2}\w+=/){print substr($0, RSTART, RLENGTH)}
}
END {}

But it is printing only one matched string.

4

Even though the question is just awk related, note, that it's much easier to achieve the same with pure grep (especially grep) or sed:

grep -o '\?[^=]*='

or

sed -n 's/.*\(\?[^=]*=\).*/\1/p'
1

Tested with below command and it worked fine

awk -F "=" '{print $1}' filename |awk -F "?" '{print "?"$2}'| sed '/^\?$/d'

output

?source=
?trackId=
?tctx=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.