Filter out random username after string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a full list of API status with lots of information like that.
I need to grep the name of the username so I can send it to another file or variable.



For example:



[ jq -r '.["username"]'


or



jq -r '.["username"]' file


But the string you provided is not proper json. It's missing the closing brackets (]) at the end and has a . instead.



jq should be available in most package managers, e.g. install it with:



sudo apt install jq



If you somehow need to use grep and have pgrep / grep -P available:



grep -Po '"username":"K[^"]*'






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 14:44









RoVo

2,224215




2,224215











  • Actually that works, but shows me for only the first occurrence. Can it be done for every string that contains username? * UPDATE* IT Works with grep , thanks a lot
    – Denis Hristov
    Nov 21 at 14:50











  • did you see my update using instead of [0] ?
    – RoVo
    Nov 21 at 14:51










  • Yes, thanks a lot !! You saved me
    – Denis Hristov
    Nov 21 at 14:52
















  • Actually that works, but shows me for only the first occurrence. Can it be done for every string that contains username? * UPDATE* IT Works with grep , thanks a lot
    – Denis Hristov
    Nov 21 at 14:50











  • did you see my update using instead of [0] ?
    – RoVo
    Nov 21 at 14:51










  • Yes, thanks a lot !! You saved me
    – Denis Hristov
    Nov 21 at 14:52















Actually that works, but shows me for only the first occurrence. Can it be done for every string that contains username? * UPDATE* IT Works with grep , thanks a lot
– Denis Hristov
Nov 21 at 14:50





Actually that works, but shows me for only the first occurrence. Can it be done for every string that contains username? * UPDATE* IT Works with grep , thanks a lot
– Denis Hristov
Nov 21 at 14:50













did you see my update using instead of [0] ?
– RoVo
Nov 21 at 14:51




did you see my update using instead of [0] ?
– RoVo
Nov 21 at 14:51












Yes, thanks a lot !! You saved me
– Denis Hristov
Nov 21 at 14:52




Yes, thanks a lot !! You saved me
– Denis Hristov
Nov 21 at 14:52












up vote
0
down vote













I have used the following command and it worked fine:



echo "[{"id":"1onyc4b1otgmtrmw37h83rjs9w","create_at":1542718790947,"update_at":1542728017634,"delete_at":0,"username":"ivan.ivanov","auth_data":""." |
sed "s/,/n/g" |
awk -F ":" '/username/print $NF'


output



ivan.ivanov





share|improve this answer


























    up vote
    0
    down vote













    I have used the following command and it worked fine:



    echo "[{"id":"1onyc4b1otgmtrmw37h83rjs9w","create_at":1542718790947,"update_at":1542728017634,"delete_at":0,"username":"ivan.ivanov","auth_data":""." |
    sed "s/,/n/g" |
    awk -F ":" '/username/print $NF'


    output



    ivan.ivanov





    share|improve this answer
























      up vote
      0
      down vote










      up vote
      0
      down vote









      I have used the following command and it worked fine:



      echo "[{"id":"1onyc4b1otgmtrmw37h83rjs9w","create_at":1542718790947,"update_at":1542728017634,"delete_at":0,"username":"ivan.ivanov","auth_data":""." |
      sed "s/,/n/g" |
      awk -F ":" '/username/print $NF'


      output



      ivan.ivanov





      share|improve this answer














      I have used the following command and it worked fine:



      echo "[{"id":"1onyc4b1otgmtrmw37h83rjs9w","create_at":1542718790947,"update_at":1542728017634,"delete_at":0,"username":"ivan.ivanov","auth_data":""." |
      sed "s/,/n/g" |
      awk -F ":" '/username/print $NF'


      output



      ivan.ivanov






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 21 at 17:12









      Bash bros

      1




      1










      answered Nov 21 at 15:35









      Praveen Kumar BS

      1,114138




      1,114138




















          Denis Hristov is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Denis Hristov is a new contributor. Be nice, and check out our Code of Conduct.












          Denis Hristov is a new contributor. Be nice, and check out our Code of Conduct.











          Denis Hristov is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483222%2ffilter-out-random-username-after-string%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay