Selecting Python String List Cell

Asked

Viewed 45 times

-1

I have to select only the last sentence containing 'M6C13'.

The text with all sentences in full is in this string path variable that receives the text through the CMD:

path = str(subprocess.check_output('aws s3 --no-sign-request ls s3://noaa-goes16/ABI-L2-CMIPF/'+str(tt.tm_year)+'/'+str(tt.tm_yday)+'/'+str(t[3]-1)+'/', shell = True))

Output of a print of the path variable:

In [2]: print(path)
In [3]: b'2019-10-29 10:11:03   73369339 OR_ABI-L2-CMIPF-M6C01_G16_s20193021300386_e20193021310094_c20193021310185.nc\r\n2019-10-29 10:20:45   75483716 OR_ABI-L2-CMIPF-M6C01_G16_s20193021310386_e20193021320094_c20193021320178.nc\r\n2019-10-29 10:30:45   77557315 OR_ABI-L2-CMIPF-M6C01_G16_s20193021320386_e20193021330094_c20193021330184.nc\r\n2019-10-29 10:40:41   79572161 OR_ABI-L2-CMIPF-M6C01_G16_s20193021330386_e20193021340094_c20193021340181.nc\r\n2019-10-29 10:50:45   81669764 OR_ABI-L2-CMIPF-M6C01_G16_s20193021340386_e20193021350094_c20193021350185.nc\r\n2019-10-29 11:00:49   83907536 OR_ABI-L2-CMIPF-M6C01_G16_s20193021350386_e20193021400094_c20193021400180.nc\r\n2019-10-29 10:12:24  413019374 OR_ABI-L2-CMIPF-M6C02_G16_s20193021300386_e20193021310094_c20193021310176.nc\r\n2019-10-29 10:21:58  419910979 OR_ABI-L2-CMIPF-M6C02_G16_s20193021310386_e20193021320094_c20193021320177.nc\r\n2019-10-29 10:31:59  426755117 OR_ABI-L2-CMIPF-M6C02_G16_s20193021320386_e20193021330094_c20193021330183.nc\r\n2019-10-29 10:42:05  433518883 OR_ABI-L2-CMIPF-M6C02_G16_s20193021330386_e20193021340094_c20193021340180.nc\r\n2019-10-29 10:51:56  440526736 OR_ABI-L2-CMIPF-M6C02_G16_s20193021340386_e20193021350094_c20193021350184.nc\r\n2019-10-29 11:02:04  447806300 OR_ABI-L2-CMIPF-M6C02_G16_s20193021350386_e20193021400094_c20193021400182.nc\r\n2019-10-29 10:11:03   83414099 OR_ABI-L2-CMIPF-M6C03_G16_s20193021300386_e20193021310094_c20193021310180.nc\r\n2019-10-29 10:20:45   85562680 OR_ABI-L2-CMIPF-M6C03_G16_s20193021310386_e20193021320094_c20193021320180.nc\r\n2019-10-29 10:30:46   87695175 OR_ABI-L2-CMIPF-M6C03_G16_s20193021320386_e20193021330094_c20193021330185.nc\r\n2019-10-29 10:40:44   89838842 OR_ABI-L2-CMIPF-M6C03_G16_s20193021330386_e20193021340094_c20193021340182.nc\r\n2019-10-29 10:50:45   92051779 OR_ABI-L2-CMIPF-M6C03_G16_s20193021340386_e20193021350094_c20193021350181.nc\r\n2019-10-29 11:00:47   94330643 OR_ABI-L2-CMIPF-M6C03_G16_s20193021350386_e20193021400094_c20193021400179.nc\r\n2019-10-29 10:10:41   13831073 OR_ABI-L2-CMIPF-M6C04_G16_s20193021300386_e20193021310094_c20193021310167.nc\r\n2019-10-29 10:20:31   14070363 OR_ABI-L2-CMIPF-M6C04_G16_s20193021310386_e20193021320094_c20193021320169.nc\r\n2019-10-29 10:30:29   14290638 OR_ABI-L2-CMIPF-M6C04_G16_s20193021320386_e20193021330094_c20193021330179.nc\r\n2019-10-29 10:40:29   14521531 OR_ABI-L2-CMIPF-M6C04_G16_s20193021330386_e20193021340094_c20193021340171.nc\r\n2019-10-29 10:50:28   14738290 OR_ABI-L2-CMIPF-M6C04_G16_s20193021340386_e20193021350094_c20193021350172.nc\r\n2019-10-29 11:00:29   14956864 OR_ABI-L2-CMIPF-M6C04_G16_s20193021350386_e20193021400094_c20193021400176.nc\r\n2019-10-29 10:10:49   79084778 OR_ABI-L2-CMIPF-M6C05_G16_s20193021300386_e20193021310094_c20193021310186.nc\r\n2019-10-29 10:20:47   81043804 OR_ABI-L2-CMIPF-M6C05_G16_s20193021310386_e20193021320094_c20193021320179.nc\r\n2019-10-29 10:30:46   83036967 OR_ABI-L2-CMIPF-M6C05_G16_s20193021320386_e20193021330094_c20193021330180.nc\r\n2019-10-29 10:40:43   85026867 OR_ABI-L2-CMIPF-M6C05_G16_s20193021330386_e20193021340094_c20193021340178.nc\r\n2019-10-29 10:50:45   87029030 OR_ABI-L2-CMIPF-M6C05_G16_s20193021340386_e20193021350094_c20193021350190.nc\r\n2019-10-29 11:00:49   89067752 OR_ABI-L2-CMIPF-M6C05_G16_s20193021350386_e20193021400094_c20193021400183.nc\r\n2019-10-29 10:10:39   18351578 OR_ABI-L2-CMIPF-M6C06_G16_s20193021300386_e20193021310101_c20193021310182.nc\r\n2019-10-29 10:20:30   18887483 OR_ABI-L2-CMIPF-M6C06_G16_s20193021310386_e20193021320100_c20193021320181.nc\r\n2019-10-29 10:30:31   19404962 OR_ABI-L2-CMIPF-M6C06_G16_s20193021320386_e20193021330100_c20193021330169.nc\r\n2019-10-29 10:40:32   19904190 OR_ABI-L2-CMIPF-M6C06_G16_s20193021330386_e20193021340100_c20193021340183.nc\r\n2019-10-29 10:50:29   20394863 OR_ABI-L2-CMIPF-M6C06_G16_s20193021340386_e20193021350100_c20193021350188.nc\r\n2019-10-29 11:00:34   20877952 OR_ABI-L2-CMIPF-M6C06_G16_s20193021350386_e20193021400100_c20193021400184.nc\r\n2019-10-29 10:10:33   26048175 OR_ABI-L2-CMIPF-M6C07_G16_s20193021300386_e20193021310107_c20193021310184.nc\r\n2019-10-29 10:20:31   26125718 OR_ABI-L2-CMIPF-M6C07_G16_s20193021310386_e20193021320105_c20193021320194.nc\r\n2019-10-29 10:30:32   26209731 OR_ABI-L2-CMIPF-M6C07_G16_s20193021320386_e20193021330106_c20193021330187.nc\r\n2019-10-29 10:40:32   26309586 OR_ABI-L2-CMIPF-M6C07_G16_s20193021330386_e20193021340106_c20193021340185.nc\r\n2019-10-29 10:50:34   26416922 OR_ABI-L2-CMIPF-M6C07_G16_s20193021340386_e20193021350106_c20193021350194.nc\r\n2019-10-29 11:00:31   26529213 OR_ABI-L2-CMIPF-M6C07_G16_s20193021350386_e20193021400106_c20193021400190.nc\r\n2019-10-29 10:10:57   19673373 OR_ABI-L2-CMIPF-M6C08_G16_s20193021300386_e20193021310094_c20193021310184.nc\r\n2019-10-29 10:20:31   19671812 OR_ABI-L2-CMIPF-M6C08_G16_s20193021310386_e20193021320094_c20193021320177.nc\r\n2019-10-29 10:30:32   19666607 OR_ABI-L2-CMIPF-M6C08_G16_s20193021320386_e20193021330094_c20193021330188.nc\r\n2019-10-29 10:40:31   19671378 OR_ABI-L2-CMIPF-M6C08_G16_s20193021330386_e20193021340094_c20193021340184.nc\r\n2019-10-29 10:50:28   19678132 OR_ABI-L2-CMIPF-M6C08_G16_s20193021340386_e20193021350094_c20193021350192.nc\r\n2019-10-29 11:00:42   19680126 OR_ABI-L2-CMIPF-M6C08_G16_s20193021350386_e20193021400094_c20193021400184.nc\r\n2019-10-29 10:10:54   18650849 OR_ABI-L2-CMIPF-M6C09_G16_s20193021300386_e20193021310100_c20193021310199.nc\r\n2019-10-29 10:20:29   18648883 OR_ABI-L2-CMIPF-M6C09_G16_s20193021310386_e20193021320100_c20193021320191.nc\r\n2019-10-29 10:30:30   18645043 OR_ABI-L2-CMIPF-M6C09_G16_s20193021320386_e20193021330101_c20193021330198.nc\r\n2019-10-29 10:40:33   18646220 OR_ABI-L2-CMIPF-M6C09_G16_s20193021330386_e20193021340100_c20193021340206.nc\r\n2019-10-29 10:50:28   18651906 OR_ABI-L2-CMIPF-M6C09_G16_s20193021340386_e20193021350100_c20193021350189.nc\r\n2019-10-29 11:00:34   18653731 OR_ABI-L2-CMIPF-M6C09_G16_s20193021350386_e20193021400100_c20193021400185.nc\r\n2019-10-29 10:10:38   22052020 OR_ABI-L2-CMIPF-M6C10_G16_s20193021300386_e20193021310106_c20193021310184.nc\r\n2019-10-29 10:20:29   22051033 OR_ABI-L2-CMIPF-M6C10_G16_s20193021310386_e20193021320106_c20193021320184.nc\r\n2019-10-29 10:30:31   22047273 OR_ABI-L2-CMIPF-M6C10_G16_s20193021320386_e20193021330106_c20193021330181.nc\r\n2019-10-29 10:40:34   22045202 OR_ABI-L2-CMIPF-M6C10_G16_s20193021330386_e20193021340106_c20193021340182.nc\r\n2019-10-29 10:50:29   22047291 OR_ABI-L2-CMIPF-M6C10_G16_s20193021340386_e20193021350106_c20193021350193.nc\r\n2019-10-29 11:00:31   22048315 OR_ABI-L2-CMIPF-M6C10_G16_s20193021350386_e20193021400106_c20193021400195.nc\r\n2019-10-29 10:10:32   27348828 OR_ABI-L2-CMIPF-M6C11_G16_s20193021300386_e20193021310094_c20193021310181.nc\r\n2019-10-29 10:20:32   27362005 OR_ABI-L2-CMIPF-M6C11_G16_s20193021310386_e20193021320094_c20193021320182.nc\r\n2019-10-29 10:30:32   27377217 OR_ABI-L2-CMIPF-M6C11_G16_s20193021320386_e20193021330094_c20193021330184.nc\r\n2019-10-29 10:40:32   27396320 OR_ABI-L2-CMIPF-M6C11_G16_s20193021330386_e20193021340094_c20193021340181.nc\r\n2019-10-29 10:50:30   27414003 OR_ABI-L2-CMIPF-M6C11_G16_s20193021340386_e20193021350094_c20193021350185.nc\r\n2019-10-29 11:00:32   27436295 OR_ABI-L2-CMIPF-M6C11_G16_s20193021350386_e20193021400094_c20193021400182.nc\r\n2019-10-29 10:10:40   24314753 OR_ABI-L2-CMIPF-M6C12_G16_s20193021300386_e20193021310100_c20193021310184.nc\r\n2019-10-29 10:20:32   24333734 OR_ABI-L2-CMIPF-M6C12_G16_s20193021310386_e20193021320100_c20193021320183.nc\r\n2019-10-29 10:30:31   24356568 OR_ABI-L2-CMIPF-M6C12_G16_s20193021320386_e20193021330100_c20193021330183.nc\r\n2019-10-29 10:40:34   24382516 OR_ABI-L2-CMIPF-M6C12_G16_s20193021330386_e20193021340100_c20193021340181.nc\r\n2019-10-29 10:50:29   24406293 OR_ABI-L2-CMIPF-M6C12_G16_s20193021340386_e20193021350100_c20193021350183.nc\r\n2019-10-29 11:00:32   24431096 OR_ABI-L2-CMIPF-M6C12_G16_s20193021350386_e20193021400100_c20193021400184.nc\r\n2019-10-29 10:10:46   26910371 OR_ABI-L2-CMIPF-M6C13_G16_s20193021300386_e20193021310106_c20193021310189.nc\r\n2019-10-29 10:20:38   26923408 OR_ABI-L2-CMIPF-M6C13_G16_s20193021310386_e20193021320105_c20193021320204.nc\r\n2019-10-29 10:30:36   26937212 OR_ABI-L2-CMIPF-M6C13_G16_s20193021320386_e20193021330106_c20193021330209.nc\r\n2019-10-29 10:40:32   26953781 OR_ABI-L2-CMIPF-M6C13_G16_s20193021330386_e20193021340106_c20193021340198.nc\r\n2019-10-29 10:50:35   26974813 OR_ABI-L2-CMIPF-M6C13_G16_s20193021340386_e20193021350106_c20193021350190.nc\r\n2019-10-29 11:00:31   26993191 OR_ABI-L2-CMIPF-M6C13_G16_s20193021350386_e20193021400106_c20193021400189.nc\r\n2019-10-29 10:10:34   26957079 OR_ABI-L2-CMIPF-M6C14_G16_s20193021300386_e20193021310094_c20193021310194.nc\r\n2019-10-29 10:20:36   26969449 OR_ABI-L2-CMIPF-M6C14_G16_s20193021310386_e20193021320094_c20193021320202.nc\r\n2019-10-29 10:30:31   26982615 OR_ABI-L2-CMIPF-M6C14_G16_s20193021320386_e20193021330094_c20193021330195.nc\r\n2019-10-29 10:40:33   26998566 OR_ABI-L2-CMIPF-M6C14_G16_s20193021330386_e20193021340094_c20193021340198.nc\r\n2019-10-29 10:50:32   27016043 OR_ABI-L2-CMIPF-M6C14_G16_s20193021340386_e20193021350094_c20193021350192.nc\r\n2019-10-29 11:00:37   27035992 OR_ABI-L2-CMIPF-M6C14_G16_s20193021350386_e20193021400094_c20193021400204.nc\r\n2019-10-29 10:10:57   26576036 OR_ABI-L2-CMIPF-M6C15_G16_s20193021300386_e20193021310100_c20193021310201.nc\r\n2019-10-29 10:20:31   26587588 OR_ABI-L2-CMIPF-M6C15_G16_s20193021310386_e20193021320100_c20193021320194.nc\r\n2019-10-29 10:30:30   26600330 OR_ABI-L2-CMIPF-M6C15_G16_s20193021320386_e20193021330100_c20193021330184.nc\r\n2019-10-29 10:40:32   26614912 OR_ABI-L2-CMIPF-M6C15_G16_s20193021330386_e20193021340100_c20193021340189.nc\r\n2019-10-29 10:50:36   26630506 OR_ABI-L2-CMIPF-M6C15_G16_s20193021340386_e20193021350100_c20193021350199.nc\r\n2019-10-29 11:00:37   26648011 OR_ABI-L2-CMIPF-M6C15_G16_s20193021350386_e20193021400100_c20193021400200.nc\r\n2019-10-29 10:10:55   20384284 OR_ABI-L2-CMIPF-M6C16_G16_s20193021300386_e20193021310106_c20193021310186.nc\r\n2019-10-29 10:20:31   20398903 OR_ABI-L2-CMIPF-M6C16_G16_s20193021310386_e20193021320106_c20193021320185.nc\r\n2019-10-29 10:30:29   20408686 OR_ABI-L2-CMIPF-M6C16_G16_s20193021320386_e20193021330106_c20193021330192.nc\r\n2019-10-29 10:40:31   20424796 OR_ABI-L2-CMIPF-M6C16_G16_s20193021330386_e20193021340106_c20193021340189.nc\r\n2019-10-29 10:50:28   20440149 OR_ABI-L2-CMIPF-M6C16_G16_s20193021340386_e20193021350106_c20193021350191.nc\r\n2019-10-29 11:00:34   20454935 OR_ABI-L2-CMIPF-M6C16_G16_s20193021350386_e20193021400106_c20193021400183.nc\r\n'

In case I would need to copy only the phrase "OR_ABI-L2-CMIPF-M6c13_g16_s20193021350386_e20193021400106_c20193021400189.nc" for another variable string.

Always the last sentence with 'M6C13'.

How could I do that automatically?

1 answer

1


You can use regex:

import re
files_list = re.findall(r'OR_[^ ]\.nc', parh)
# Se precisar só do primeiro arquivo
file = files_list[0]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.