正则表达式从json子字段中获取URL字段

时间:2017-10-23 01:31:52

标签: json regex bash shell grep

我有以下文件:

{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77rzm3", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Eyes Wide Shut (1999) An argument about fidelity sends a married physician reeling into the night, where he finds himself in a surreal succession of sexual encounters. Starring Tom Cruise", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 1055, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77rzm3", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77rzm3/us_eyes_wide_shut_1999_an_argument_about_fidelity/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508598049.0, "url": "https://www.netflix.com/title/5670434", "whitelist_status": "all_ads", "quarantine": false, "author": "gerrardslips", "created_utc": 1508569249.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 1055, "media": null, "num_comments": 141, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "self.NetflixBestOf", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>Last year I posted <a href=\"https://www.reddit.com/r/NetflixBestOf/comments/56ibei/discussion_direct_links_to_halloween_episodes_of/\">this</a> and I haven't seen anyone post it again this year.  But sad to say so many of these episodes are gone now.  </p>\n\n<p>I dug up a few more, and if you want to add your own, you can get ideas here: <a href=\"https://en.wikipedia.org/wiki/List_of_Halloween_television_specials\">https://en.wikipedia.org/wiki/List_of_Halloween_television_specials</a></p>\n\n<p>Links:</p>\n\n<p>Office - Halloween, <a href=\"https://www.netflix.com/watch/70069637?trackId=13752289&tctx=0%2C4%2C6c95c505-fbda-4094-9d44-9257b64fc661-55459680\">S02.E05</a></p>\n\n<p>Office - Employee Transfer, <a href=\"https://www.netflix.com/watch/70126227?trackId=13752289&tctx=0%2C5%2C91d0240b-5805-4974-8dde-6cdce0cba888-86812819\">S05.E06</a></p>\n\n<p>Office - Costume Contest, <a href=\"https://www.netflix.com/watch/70189011?trackId=13752289&tctx=0%2C5%2C6c95c505-fbda-4094-9d44-9257b64fc661-55459680\">S07.E06</a></p>\n\n<p>Office - Spooked, <a href=\"https://www.netflix.com/watch/70210969?trackId=13752289&tctx=0%2C4%2C91d0240b-5805-4974-8dde-6cdce0cba888-86812819\">S08.E05</a></p>\n\n<p>Parks and Rec - Greg Pikitis, <a href=\"https://www.netflix.com/watch/70152017?trackId=13752289&tctx=0%2C6%2C3eecb087-07c4-40c2-8b23-0e254d28f15d-86849891\">S02.E07</a></p>\n\n<p>Parks and Rec - Meet n Greet, <a href=\"https://www.netflix.com/watch/70210920?trackId=13752289&tctx=0%2C4%2C925890fd-f12c-4e1b-a5dc-4193c77e689b-55577276\">S04.E05</a></p>\n\n<p>Parks and Rec - Halloween Surprise, <a href=\"https://www.netflix.com/watch/70286785?trackId=13752289&tctx=0%2C4%2C925890fd-f12c-4e1b-a5dc-4193c77e689b-55577276\">S05.E05</a></p>\n\n<p>70s Show - Halloween, <a href=\"https://www.netflix.com/watch/70165229?trackId=13752289&tctx=0%2C4%2Cb7441e12-4218-4667-9d79-1013f6c6fd14-86967765\">S02.E05</a></p>\n\n<p>70s Show - Too Old to Trick or Treat, Too Young to Die, <a href=\"https://www.netflix.com/watch/70165250?trackId=13752289&tctx=0%2C3%2Cb7441e12-4218-4667-9d79-1013f6c6fd14-86967765\">S03.E04</a></p>\n\n<p>Friends - The One with the Halloween Party, <a href=\"https://www.netflix.com/watch/70274172?trackId=13752289&tctx=0%2C5%2C742ad784-352a-4409-a00e-be3f78a5fcb7-85533521\">S08.E06</a></p>\n\n<p>F is for Family - F is for Halloween, <a href=\"https://www.netflix.com/watch/80028556?trackId=13752289&tctx=0%2C3%2Ca634730d-f8c8-481a-a570-38f2b486c57a-86060071\">S01.E04</a></p>\n\n<p>Family Guy - Halloween on Spooner Street, <a href=\"https://www.netflix.com/watch/70251733?trackId=13752289&tctx=0%2C4%2C3f6bb27b-4426-4e60-a68e-e96d2bb69df2-86109839\">S09.E05</a></p>\n\n<p>Family Guy - Quagmire's Quagmire, <a href=\"https://www.netflix.com/watch/80018564?trackId=13752289&tctx=0%2C2%2C3f6bb27b-4426-4e60-a68e-e96d2bb69df2-86109839\">S12.E03</a></p>\n</div><!-- SC_ON -->", "selftext": "Last year I posted [this](https://www.reddit.com/r/NetflixBestOf/comments/56ibei/discussion_direct_links_to_halloween_episodes_of/) and I haven't seen anyone post it again this year.  But sad to say so many of these episodes are gone now.  \n\nI dug up a few more, and if you want to add your own, you can get ideas here: https://en.wikipedia.org/wiki/List_of_Halloween_television_specials\n\nLinks:\n\nOffice - Halloween, [S02.E05](https://www.netflix.com/watch/70069637?trackId=13752289&tctx=0%2C4%2C6c95c505-fbda-4094-9d44-9257b64fc661-55459680)\n\nOffice - Employee Transfer, [S05.E06](https://www.netflix.com/watch/70126227?trackId=13752289&tctx=0%2C5%2C91d0240b-5805-4974-8dde-6cdce0cba888-86812819)\n\nOffice - Costume Contest, [S07.E06](https://www.netflix.com/watch/70189011?trackId=13752289&tctx=0%2C5%2C6c95c505-fbda-4094-9d44-9257b64fc661-55459680)\n\nOffice - Spooked, [S08.E05](https://www.netflix.com/watch/70210969?trackId=13752289&tctx=0%2C4%2C91d0240b-5805-4974-8dde-6cdce0cba888-86812819)\n\nParks and Rec - Greg Pikitis, [S02.E07](https://www.netflix.com/watch/70152017?trackId=13752289&tctx=0%2C6%2C3eecb087-07c4-40c2-8b23-0e254d28f15d-86849891)\n\nParks and Rec - Meet n Greet, [S04.E05](https://www.netflix.com/watch/70210920?trackId=13752289&tctx=0%2C4%2C925890fd-f12c-4e1b-a5dc-4193c77e689b-55577276)\n\nParks and Rec - Halloween Surprise, [S05.E05](https://www.netflix.com/watch/70286785?trackId=13752289&tctx=0%2C4%2C925890fd-f12c-4e1b-a5dc-4193c77e689b-55577276)\n\n70s Show - Halloween, [S02.E05](https://www.netflix.com/watch/70165229?trackId=13752289&tctx=0%2C4%2Cb7441e12-4218-4667-9d79-1013f6c6fd14-86967765)\n\n70s Show - Too Old to Trick or Treat, Too Young to Die, [S03.E04](https://www.netflix.com/watch/70165250?trackId=13752289&tctx=0%2C3%2Cb7441e12-4218-4667-9d79-1013f6c6fd14-86967765)\n\nFriends - The One with the Halloween Party, [S08.E06](https://www.netflix.com/watch/70274172?trackId=13752289&tctx=0%2C5%2C742ad784-352a-4409-a00e-be3f78a5fcb7-85533521)\n\nF is for Family - F is for Halloween, [S01.E04](https://www.netflix.com/watch/80028556?trackId=13752289&tctx=0%2C3%2Ca634730d-f8c8-481a-a570-38f2b486c57a-86060071)\n\nFamily Guy - Halloween on Spooner Street, [S09.E05](https://www.netflix.com/watch/70251733?trackId=13752289&tctx=0%2C4%2C3f6bb27b-4426-4e60-a68e-e96d2bb69df2-86109839)\n\nFamily Guy - Quagmire's Quagmire, [S12.E03](https://www.netflix.com/watch/80018564?trackId=13752289&tctx=0%2C2%2C3f6bb27b-4426-4e60-a68e-e96d2bb69df2-86109839)\n\n", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77toj0", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[META] Direct links to Halloween episodes.", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 67, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": true, "parent_whitelist_status": "all_ads", "name": "t3_77toj0", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77toj0/meta_direct_links_to_halloween_episodes/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508625121.0, "url": "https://www.reddit.com/r/NetflixBestOf/comments/77toj0/meta_direct_links_to_halloween_episodes/", "whitelist_status": "all_ads", "quarantine": false, "author": "tingmakpuk", "created_utc": 1508596321.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 67, "media": null, "num_comments": 2, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77rm11", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Wheelman (2017) Getaway driver in a botched robbery puts his skills and smarts to the test when he receives shocking orders from an unknown caller", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 114, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77rm11", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77rm11/us_wheelman_2017_getaway_driver_in_a_botched/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508591782.0, "url": "https://www.netflix.com/title/80113669?s=i&trkid=13752289", "whitelist_status": "all_ads", "quarantine": false, "author": "fields", "created_utc": 1508562982.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 114, "media": null, "num_comments": 16, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77mg82", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] 1922 (2017) A farmer pens a confession admitting to his wife's murder, but her death is just the beginning of a macabre tale. Based on Stephen King's novella.", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 719, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77mg82", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77mg82/us_1922_2017_a_farmer_pens_a_confession_admitting/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508538724.0, "url": "https://www.netflix.com/title/80135164", "whitelist_status": "all_ads", "quarantine": false, "author": "youjokingright", "created_utc": 1508509924.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 719, "media": null, "num_comments": 49, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77iepy", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Mean Girls (2004) Cady joins her new high school's most powerful clique -- but there's hell to pay when the ex-boyfriend of the clique's leader wants to be Cady's guy. Starring Lindsay Lohan", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 2440, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77iepy", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77iepy/us_mean_girls_2004_cady_joins_her_new_high/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508486071.0, "url": "https://www.netflix.com/title/60034551", "whitelist_status": "all_ads", "quarantine": false, "author": "gerrardslips", "created_utc": 1508457271.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 2440, "media": null, "num_comments": 162, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "self.NetflixBestOf", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>My region is the US, other than that the title pretty much says it all. I\u2019d prefer movies over shows, but I welcome all suggestions. Other than not being horror, I would also like to get away from grim and serious and thriller. Comedies, feel good movies, entertaining dramas, even kids movies that are good for adults. </p>\n\n<p>Hit me!</p>\n</div><!-- SC_ON -->", "selftext": "My region is the US, other than that the title pretty much says it all. I\u2019d prefer movies over shows, but I welcome all suggestions. Other than not being horror, I would also like to get away from grim and serious and thriller. Comedies, feel good movies, entertaining dramas, even kids movies that are good for adults. \n\nHit me!", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77rc7y", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[Request] I have been watching an absurd amount of horror since it\u2019s October, but now I need a palate cleanser", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 6, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": true, "parent_whitelist_status": "all_ads", "name": "t3_77rc7y", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77rc7y/request_i_have_been_watching_an_absurd_amount_of/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508587814.0, "url": "https://www.reddit.com/r/NetflixBestOf/comments/77rc7y/request_i_have_been_watching_an_absurd_amount_of/", "whitelist_status": "all_ads", "quarantine": false, "author": "CinnamonSwisher", "created_utc": 1508559014.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 6, "media": null, "num_comments": 10, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "self.NetflixBestOf", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>I like star wars and the lion king, not sure what to watch now \ud83d\ude33</p>\n\n<p>Edit: I'm going to watch Point Break over my holiday break, but thanks for all the great suggestions!</p>\n</div><!-- SC_ON -->", "selftext": "I like star wars and the lion king, not sure what to watch now \ud83d\ude33\n\nEdit: I'm going to watch Point Break over my holiday break, but thanks for all the great suggestions!", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77q8iw", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[REQUEST] Are there any movies with mentally ill or disabled people trying to climb a mountain or something?", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 7, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": 1508604821.0, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": true, "parent_whitelist_status": "all_ads", "name": "t3_77q8iw", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77q8iw/request_are_there_any_movies_with_mentally_ill_or/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508574105.0, "url": "https://www.reddit.com/r/NetflixBestOf/comments/77q8iw/request_are_there_any_movies_with_mentally_ill_or/", "whitelist_status": "all_ads", "quarantine": false, "author": "Diddler_kid", "created_utc": 1508545305.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 7, "media": null, "num_comments": 15, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77kotv", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Best in Show (2000) Master mockumentarian Christopher Guest turns his cameras on the neurotic contestants vying for top honors in a highly competitive dog show.", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 162, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77kotv", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77kotv/us_best_in_show_2000_master_mockumentarian/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508514822.0, "url": "https://www.netflix.com/title/60002428", "whitelist_status": "all_ads", "quarantine": false, "author": "gerrardslips", "created_utc": 1508486022.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 162, "media": null, "num_comments": 15, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77koxy", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Trading Places (1983) A streetwise hustler trades places with a wealthy investment executive as part of a bet cooked up by the rich, greedy Duke brothers. Starring Eddie Murphy", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 61, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77koxy", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77koxy/us_trading_places_1983_a_streetwise_hustler/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508514883.0, "url": "https://www.netflix.com/title/60011484", "whitelist_status": "all_ads", "quarantine": false, "author": "gerrardslips", "created_utc": 1508486083.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 61, "media": null, "num_comments": 8, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77kfwh", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] OtherLife (2017): After inventing a drug that induces time-compressed virtual realities, young Ren grapples with partner Sam over how to use their powerful creation.", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 28, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77kfwh", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77kfwh/us_otherlife_2017_after_inventing_a_drug_that/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508510695.0, "url": "https://www.netflix.com/title/80190841", "whitelist_status": "all_ads", "quarantine": false, "author": "Kevin241", "created_utc": 1508481895.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 28, "media": null, "num_comments": 4, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}
{"domain": "netflix.com", "approved_at_utc": null, "banned_by": null, "media_embed": {}, "subreddit": "NetflixBestOf", "selftext_html": null, "selftext": "", "likes": null, "suggested_sort": null, "user_reports": [], "secure_media": null, "is_reddit_media_domain": false, "saved": false, "id": "77d6xt", "banned_at_utc": null, "view_count": null, "archived": false, "clicked": false, "report_reasons": null, "title": "[US] Futurama (2013) A pizza delivery boy awakens in the 31st century after 1,000 years of cryogenic preservation and finds a job at an interplanetary delivery service. Seasons 7-10", "num_crossposts": 0, "link_flair_text": null, "mod_reports": [], "can_mod_post": false, "is_crosspostable": false, "pinned": false, "score": 1335, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2ro0h", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "contest_mode": false, "gilded": 0, "downs": 0, "brand_safe": true, "secure_media_embed": {}, "removal_reason": null, "author_flair_text": null, "stickied": false, "can_gild": false, "is_self": false, "parent_whitelist_status": "all_ads", "name": "t3_77d6xt", "spoiler": false, "permalink": "/r/NetflixBestOf/comments/77d6xt/us_futurama_2013_a_pizza_delivery_boy_awakens_in/", "subreddit_type": "public", "locked": false, "hide_score": false, "created": 1508431704.0, "url": "https://www.netflix.com/title/70153380", "whitelist_status": "all_ads", "quarantine": false, "author": "gerrardslips", "created_utc": 1508402904.0, "subreddit_name_prefixed": "r/NetflixBestOf", "ups": 1335, "media": null, "num_comments": 104, "visited": false, "num_reports": null, "is_video": false, "distinguished": null}

我需要打印url字段的值(如果可用)。例如:

https://www.reddit.com/r/NetflixBestOf/comments/736jlh/meta_netflixbestof_5th_annual_31_days_of_horror/
https://www.netflix.com/title/6002748

这是我目前的正则表达式(顺便使用egrep格式):

egrep -o '"url": *"[^"]*,'

它没有对特殊情况进行任何检查,但是它不应该至少输出1个URL吗?不确定我的问题是什么,感谢任何帮助!

3 个答案:

答案 0 :(得分:2)

可能你在最后一个逗号之前错过了一个引号:

'"url": *"[^"]*",'

使用非捕获组:

'(?:"url": *")([^"]*)(?:",)'

答案 1 :(得分:2)

技巧不是egrep(grep -E),但你必须使用Perl正则表达式

grep -Po '"url"\s*:\s*"\K(.+?)(?=")'

答案 2 :(得分:0)

根据@Andy的建议,建议您将数据作为结构化数据处理,在您的情况下是JSON,对吗?

几行Python,Perl或任何你喜欢的内容都会有所帮助:

import json
with open("input.txt") as f:
    for jdata in f:
        print(jdata)
        data = json.loads(jdata)
        print(data["url"])