How to grep out the first file path in python
up vote
0
down vote
favorite
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.
python regex grep
add a comment |
up vote
0
down vote
favorite
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.
python regex grep
Will the file always begin withhdfs
?
– Rodolfo Donã Hosp
Nov 5 at 17:01
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
python regex grep
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.
python regex grep
python regex grep
asked Nov 5 at 16:59
mdivk
53821024
53821024
Will the file always begin withhdfs
?
– Rodolfo Donã Hosp
Nov 5 at 17:01
add a comment |
Will the file always begin withhdfs
?
– Rodolfo Donã Hosp
Nov 5 at 17:01
Will the file always begin with
hdfs
?– Rodolfo Donã Hosp
Nov 5 at 17:01
Will the file always begin with
hdfs
?– Rodolfo Donã Hosp
Nov 5 at 17:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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]
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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]
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
add a comment |
up vote
1
down vote
accepted
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]
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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]
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]
answered Nov 5 at 17:03
wpercy
6,04841933
6,04841933
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
add a comment |
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
Thank you, yes I just realized that :)
– mdivk
Nov 5 at 17:04
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
If your format is really fixed, as in an auto generated log file, this answer is probably easiest than using a length regex to fish out the path +1.
– Tim Biegeleisen
Nov 5 at 17:06
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53158892%2fhow-to-grep-out-the-first-file-path-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Will the file always begin with
hdfs
?– Rodolfo Donã Hosp
Nov 5 at 17:01