Extract multiple occurrences in the same line of a string between two delimiters
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="
Example input (two long lines):
d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel
start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike
Output desired is:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
All of the script examples I've seen only seem to work for the first occurrence in a line.
text-processing awk sed
add a comment |Â
up vote
1
down vote
favorite
This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="
Example input (two long lines):
d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel
start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike
Output desired is:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
All of the script examples I've seen only seem to work for the first occurrence in a line.
text-processing awk sed
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="
Example input (two long lines):
d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel
start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike
Output desired is:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
All of the script examples I've seen only seem to work for the first occurrence in a line.
text-processing awk sed
This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="
Example input (two long lines):
d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel
start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike
Output desired is:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
All of the script examples I've seen only seem to work for the first occurrence in a line.
text-processing awk sed
text-processing awk sed
edited Aug 7 at 5:40
jasonwryan
47.1k14127178
47.1k14127178
asked Aug 7 at 3:30
CanRegExtoSaveMyLife
61
61
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
One way to do this is:
grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'
Where we use GNU grep
with the Perl
feature turned on and the -o
option to output just the matche(s), rather than the default whole line when a match is found.
Output:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
up vote
0
down vote
Another way:
sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
One way to do this is:
grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'
Where we use GNU grep
with the Perl
feature turned on and the -o
option to output just the matche(s), rather than the default whole line when a match is found.
Output:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
up vote
1
down vote
One way to do this is:
grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'
Where we use GNU grep
with the Perl
feature turned on and the -o
option to output just the matche(s), rather than the default whole line when a match is found.
Output:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
up vote
1
down vote
up vote
1
down vote
One way to do this is:
grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'
Where we use GNU grep
with the Perl
feature turned on and the -o
option to output just the matche(s), rather than the default whole line when a match is found.
Output:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
One way to do this is:
grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'
Where we use GNU grep
with the Perl
feature turned on and the -o
option to output just the matche(s), rather than the default whole line when a match is found.
Output:
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
answered Aug 7 at 3:48
Rakesh Sharma
57513
57513
add a comment |Â
add a comment |Â
up vote
0
down vote
Another way:
sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
up vote
0
down vote
Another way:
sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Another way:
sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
Another way:
sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
id="3af3a73f26a63a"
id="7ab8273f273e7273f82c2"
id="973a72b72c72df12a2"
id="83hd826ab712cc71"
id="7612364bab72a"
answered Aug 7 at 8:38
RudiC
1,1837
1,1837
add a comment |Â
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%2funix.stackexchange.com%2fquestions%2f460941%2fextract-multiple-occurrences-in-the-same-line-of-a-string-between-two-delimiters%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