extract substring (filename) with bash/grep/awk/etc
up vote
1
down vote
favorite
I have a console output process string like this:
plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All!.1976.mkv -filter_complex [0:0]yadif[0];[0]scale=w=768:h=576[1];[1]format=pix_fmts=yuv420p|nv12[2] -filter_complex [0:1] aresample=async=1:ocl='stereo':osr=48000[3] -map [2] -metadata:s:0 language=eng -codec:0 libx264 -crf:0 16 -maxrate:0 7752k -bufsize:0 15504k -r:0 25 -preset:0 veryfast -x264opts:0 subme=1:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none -force_key_frames:0 expr:gte(t,0+n_forced*5) -map [3] -metadata:s:1 language=rus -codec:1 aac -b:1 256k -segment_format mpegts -f ssegment -individual_header_trailer 0 -segment_time 5 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 -segment_list http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/seglist -segment_list_type csv -segment_list_size 2147483647 -segment_list_separate_stream_times 1 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel quiet -loglevel_plex error -progressurl http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/progress
How can I easily extract this filename /volume1/video/classic/Now We've Seen It All!.1976.mkv
?
Path and file extensions can be different (.avi,.mkv,.mov,.mpeg).
command-line bash text-processing
add a comment |
up vote
1
down vote
favorite
I have a console output process string like this:
plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All!.1976.mkv -filter_complex [0:0]yadif[0];[0]scale=w=768:h=576[1];[1]format=pix_fmts=yuv420p|nv12[2] -filter_complex [0:1] aresample=async=1:ocl='stereo':osr=48000[3] -map [2] -metadata:s:0 language=eng -codec:0 libx264 -crf:0 16 -maxrate:0 7752k -bufsize:0 15504k -r:0 25 -preset:0 veryfast -x264opts:0 subme=1:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none -force_key_frames:0 expr:gte(t,0+n_forced*5) -map [3] -metadata:s:1 language=rus -codec:1 aac -b:1 256k -segment_format mpegts -f ssegment -individual_header_trailer 0 -segment_time 5 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 -segment_list http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/seglist -segment_list_type csv -segment_list_size 2147483647 -segment_list_separate_stream_times 1 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel quiet -loglevel_plex error -progressurl http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/progress
How can I easily extract this filename /volume1/video/classic/Now We've Seen It All!.1976.mkv
?
Path and file extensions can be different (.avi,.mkv,.mov,.mpeg).
command-line bash text-processing
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a console output process string like this:
plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All!.1976.mkv -filter_complex [0:0]yadif[0];[0]scale=w=768:h=576[1];[1]format=pix_fmts=yuv420p|nv12[2] -filter_complex [0:1] aresample=async=1:ocl='stereo':osr=48000[3] -map [2] -metadata:s:0 language=eng -codec:0 libx264 -crf:0 16 -maxrate:0 7752k -bufsize:0 15504k -r:0 25 -preset:0 veryfast -x264opts:0 subme=1:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none -force_key_frames:0 expr:gte(t,0+n_forced*5) -map [3] -metadata:s:1 language=rus -codec:1 aac -b:1 256k -segment_format mpegts -f ssegment -individual_header_trailer 0 -segment_time 5 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 -segment_list http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/seglist -segment_list_type csv -segment_list_size 2147483647 -segment_list_separate_stream_times 1 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel quiet -loglevel_plex error -progressurl http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/progress
How can I easily extract this filename /volume1/video/classic/Now We've Seen It All!.1976.mkv
?
Path and file extensions can be different (.avi,.mkv,.mov,.mpeg).
command-line bash text-processing
I have a console output process string like this:
plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All!.1976.mkv -filter_complex [0:0]yadif[0];[0]scale=w=768:h=576[1];[1]format=pix_fmts=yuv420p|nv12[2] -filter_complex [0:1] aresample=async=1:ocl='stereo':osr=48000[3] -map [2] -metadata:s:0 language=eng -codec:0 libx264 -crf:0 16 -maxrate:0 7752k -bufsize:0 15504k -r:0 25 -preset:0 veryfast -x264opts:0 subme=1:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none -force_key_frames:0 expr:gte(t,0+n_forced*5) -map [3] -metadata:s:1 language=rus -codec:1 aac -b:1 256k -segment_format mpegts -f ssegment -individual_header_trailer 0 -segment_time 5 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 -segment_list http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/seglist -segment_list_type csv -segment_list_size 2147483647 -segment_list_separate_stream_times 1 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel quiet -loglevel_plex error -progressurl http://127.0.0.1:32400/video/:/transcode/session/vgh38cdsdmd70euan70xdqh8/cf3a3188-52f9-4b26-8b63-1c348a7c9348/progress
How can I easily extract this filename /volume1/video/classic/Now We've Seen It All!.1976.mkv
?
Path and file extensions can be different (.avi,.mkv,.mov,.mpeg).
command-line bash text-processing
command-line bash text-processing
edited Nov 26 at 19:59
dessert
21.5k55896
21.5k55896
asked Nov 26 at 14:01
Vlad G
61
61
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
Assuming the arguments are always in the same order:
grep -oP '(?<=-i ).*?(?= -filter_complex)'
Explanation:
-o
- Print only the matching part of the line
-P
- Use Perl extensions
(?<=-i )
- Lookbehind for-i
.*?
- Match zero or more characters, non-greedily
(?= -filter_complex)
- Lookahead for-filter_complex
add a comment |
up vote
1
down vote
You can filter out the string between “-i ” and “ -filter_complex” with:
sed 's/.*-i (.*) -filter_complex.*/1/'
It saves the string between these two as group 1 and replaces the whole line by it.
Example run
$ echo "plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All"'!'".1976.mkv -filter_complex" | sed 's/.*-i (.*) -filter_complex.*/1/'
/volume1/video/classic/Now We've Seen It All!.1976.mkv
add a comment |
up vote
0
down vote
It's not easy and error-prone without using a proper options parser such as getopts
but you could try using ack-grep
like that:
ps ... | ack -o '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
You can also use GNU grep
experimental -P
option:
ps ... | grep -oP '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Assuming the arguments are always in the same order:
grep -oP '(?<=-i ).*?(?= -filter_complex)'
Explanation:
-o
- Print only the matching part of the line
-P
- Use Perl extensions
(?<=-i )
- Lookbehind for-i
.*?
- Match zero or more characters, non-greedily
(?= -filter_complex)
- Lookahead for-filter_complex
add a comment |
up vote
1
down vote
Assuming the arguments are always in the same order:
grep -oP '(?<=-i ).*?(?= -filter_complex)'
Explanation:
-o
- Print only the matching part of the line
-P
- Use Perl extensions
(?<=-i )
- Lookbehind for-i
.*?
- Match zero or more characters, non-greedily
(?= -filter_complex)
- Lookahead for-filter_complex
add a comment |
up vote
1
down vote
up vote
1
down vote
Assuming the arguments are always in the same order:
grep -oP '(?<=-i ).*?(?= -filter_complex)'
Explanation:
-o
- Print only the matching part of the line
-P
- Use Perl extensions
(?<=-i )
- Lookbehind for-i
.*?
- Match zero or more characters, non-greedily
(?= -filter_complex)
- Lookahead for-filter_complex
Assuming the arguments are always in the same order:
grep -oP '(?<=-i ).*?(?= -filter_complex)'
Explanation:
-o
- Print only the matching part of the line
-P
- Use Perl extensions
(?<=-i )
- Lookbehind for-i
.*?
- Match zero or more characters, non-greedily
(?= -filter_complex)
- Lookahead for-filter_complex
edited Nov 26 at 14:41
answered Nov 26 at 14:27
wjandrea
8,05142258
8,05142258
add a comment |
add a comment |
up vote
1
down vote
You can filter out the string between “-i ” and “ -filter_complex” with:
sed 's/.*-i (.*) -filter_complex.*/1/'
It saves the string between these two as group 1 and replaces the whole line by it.
Example run
$ echo "plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All"'!'".1976.mkv -filter_complex" | sed 's/.*-i (.*) -filter_complex.*/1/'
/volume1/video/classic/Now We've Seen It All!.1976.mkv
add a comment |
up vote
1
down vote
You can filter out the string between “-i ” and “ -filter_complex” with:
sed 's/.*-i (.*) -filter_complex.*/1/'
It saves the string between these two as group 1 and replaces the whole line by it.
Example run
$ echo "plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All"'!'".1976.mkv -filter_complex" | sed 's/.*-i (.*) -filter_complex.*/1/'
/volume1/video/classic/Now We've Seen It All!.1976.mkv
add a comment |
up vote
1
down vote
up vote
1
down vote
You can filter out the string between “-i ” and “ -filter_complex” with:
sed 's/.*-i (.*) -filter_complex.*/1/'
It saves the string between these two as group 1 and replaces the whole line by it.
Example run
$ echo "plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All"'!'".1976.mkv -filter_complex" | sed 's/.*-i (.*) -filter_complex.*/1/'
/volume1/video/classic/Now We've Seen It All!.1976.mkv
You can filter out the string between “-i ” and “ -filter_complex” with:
sed 's/.*-i (.*) -filter_complex.*/1/'
It saves the string between these two as group 1 and replaces the whole line by it.
Example run
$ echo "plex 24029 33.3 3.4 330284 63656 ? Sl 22:37 6:01 /volume1/@appstore/Plex Media Server/Plex Transcoder -codec:0 mpeg2video -codec:1 ac3 -i /volume1/video/classic/Now We've Seen It All"'!'".1976.mkv -filter_complex" | sed 's/.*-i (.*) -filter_complex.*/1/'
/volume1/video/classic/Now We've Seen It All!.1976.mkv
answered Nov 26 at 20:14
dessert
21.5k55896
21.5k55896
add a comment |
add a comment |
up vote
0
down vote
It's not easy and error-prone without using a proper options parser such as getopts
but you could try using ack-grep
like that:
ps ... | ack -o '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
You can also use GNU grep
experimental -P
option:
ps ... | grep -oP '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
add a comment |
up vote
0
down vote
It's not easy and error-prone without using a proper options parser such as getopts
but you could try using ack-grep
like that:
ps ... | ack -o '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
You can also use GNU grep
experimental -P
option:
ps ... | grep -oP '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
add a comment |
up vote
0
down vote
up vote
0
down vote
It's not easy and error-prone without using a proper options parser such as getopts
but you could try using ack-grep
like that:
ps ... | ack -o '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
You can also use GNU grep
experimental -P
option:
ps ... | grep -oP '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
It's not easy and error-prone without using a proper options parser such as getopts
but you could try using ack-grep
like that:
ps ... | ack -o '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
You can also use GNU grep
experimental -P
option:
ps ... | grep -oP '-i .+?(-|$)' | sed 's,^-i ,,' | sed 's,-$,,'
answered Nov 26 at 14:18
Arkadiusz Drabczyk
97149
97149
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096181%2fextract-substring-filename-with-bash-grep-awk-etc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown