Filter out random username after string
Clash 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[^"]*'
answered Nov 21 at 14:44
RoVo
2,224215
2,224215
add a comment |
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 usinginstead 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
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 21 at 17:12
Bash bros
1
1
answered Nov 21 at 15:35
Praveen Kumar BS
1,114138
1,114138
add a comment |
add a comment |
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.
Denis Hristov is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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