shell - Parsing the required field from an URL in awk -


i have requirement parse required field url. purpose need traverse url letter letter since there no space separation between words . not able . have tried below

awk '{fs = "";for (i = 2; <= nf; i++) {print $i}}'  file 

the file contains

https://stackoverflow.com/questions/ask/submit?s=sddasdsadsomefield=8171wantedfield=121212somefield=1201212...

so idea traverse url letter letter , reach required field .. not able that. suggestions please

this work, assuming pattern = , *.

echo "http://stackoverflow.com/questions/ask/submit?s=sddasdsadsomefield=8171*wantedfield=121212*somefield=1201212..." |awk -f "[*=]" -vfieldname="wantedfield"  '{for (i=1;i<=nf;i++){if(match($i,fieldname)){printf "%s\t", $(i+1)}};printf "\n"}' 

output:

121212 

changing somefield target field:

echo "http://stackoverflow.com/questions/ask/submit?s=sddasdsadsomefield=8171*wantedfield=121212*somefield=1201212..." | awk -f "[*=]" -vfieldname="somefield"  '{for (i=1;i<=nf;i++){if(match($i,fieldname)){printf "%s\t", $(i+1)}};printf "\n"}' 

results in:

8171    1201212... 

Comments

  1. Sky Casino in Jordan 7-star Discounts - Air Jordan7
    Shop for SKYCITY's 7 STAR air jordan 18 retro red suede online store discount code show air jordan 18 retro red suede and promo. Save with our latest SKYCITY jordan 18 white royal blue outlet promotional codes & free promo where can i buy air jordan 18 retro red suede for more than where to get air jordan 18 retro red 15 countries.

    ReplyDelete

Post a Comment

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -