[英]How to grep out the first file path in python
我总是对正则表达式感到头疼,但我猜可能是这样做的方法。 这是我的字符串:
-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
我要grep列出的是文件的完整路径:
HDFS://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet
非常感谢你。
为什么不只取空格分隔的字符串的最后一个值?
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.