I have a file that contains lines that look like this:
username1
username2
./2011-05-25-0.json.gz:{"repo":{"url":"https://api.github.dev/repos//","name":"/"},"type":"FollowEvent","public":true,"created_at":"2011-05-25","payload":{"target":{"gravatar_id":"5e17","id":144929,"repos":12,"followers":1,"login":"username3"}},"actor":{"gravatar_id":"dec","id":21,"url":"https://api.github.dev/users/user","avatar_url":"https://secure.gravatar.com/avatar/decc?d=http://github.dev%2Fimages%2Fgravatars%2Fgravatar-user-420.png","login":"username4"},"id":"14"}
./2011-05-25-0.json.gz:{"repo":{"url":"https://api.github.dev/repos//","name":"/"},"type":"FollowEvent","public":true,"created_at":"2011-05-25","payload":{"target":{"gravatar_id":"f9ed","id":82,"repos":5,"followers":4,"login":"username5"}},"actor":{"gravatar_id":"decc93","id":21,"url":"https://api.github.dev/users/username","avatar_url":"https://secure.gravatar.com/avatar/de?d=http://github.dev.user-420.png","login":"username6"},"id":"147"}
I would like to obtain a file that contains:
username1
username2
username4
username6
That is, if the string "login":
occurs on a line, then obtain the string contained in "
immediately after the second occurrence of "login"
. Otherwise, keep the line untouched.
How can I do this with grep
, or sed
?