简体   繁体   中英

How to grep out the first file path in python

I am always headache with regex but guess it might be the way to do it. Here is the string I have:

-rw-rw----+  3 userabc clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet

All I want to grep out is the file's full path:

hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet

Thank you very much.

Why not just take the last value of the space-separated string?

x = "-rw-rw----+  3 userabc clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet"
parts = [y for y in x.split(' ') if y]  # removes empty strings
fname = parts[-1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM