grep sentence between (and including) two patterns
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I want to extract sentences which start with
https://www.instagram.com/p/
and end with
/
For example, I want to extract the following without the x's
ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ
I have already tried
grep "https://www.instagram.com/p/*/"
However, it is not working.
linux grep
add a comment |Â
up vote
2
down vote
favorite
I want to extract sentences which start with
https://www.instagram.com/p/
and end with
/
For example, I want to extract the following without the x's
ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ
I have already tried
grep "https://www.instagram.com/p/*/"
However, it is not working.
linux grep
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to extract sentences which start with
https://www.instagram.com/p/
and end with
/
For example, I want to extract the following without the x's
ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ
I have already tried
grep "https://www.instagram.com/p/*/"
However, it is not working.
linux grep
I want to extract sentences which start with
https://www.instagram.com/p/
and end with
/
For example, I want to extract the following without the x's
ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ
I have already tried
grep "https://www.instagram.com/p/*/"
However, it is not working.
linux grep
edited Aug 6 at 16:38
SivaPrasath
3,68311636
3,68311636
asked Aug 6 at 16:08
Yusuke Otsubo
132
132
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
Try the following regular expression, https://www.instagram.com/p/[^/]+/
#!/bin/bash
data="ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ"
echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'
The magic part is [^/]+/
, it grabs everything up to the next forward slash.
Sample output from the above script.
zb@server ~ $ ./tmp.sh
https://www.instagram.com/p/BRhNDg5jne7/
It works! Thank you!
â Yusuke Otsubo
yesterday
add a comment |Â
up vote
3
down vote
Using grep :
echo "ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"
output:
https://www.instagram.com/p/BRhNDg5jne7/
add a comment |Â
up vote
0
down vote
no need of perl regex You can try :
grep -o "https://www.instagram.com/.*/"
1
You probably want a non-greedy match, or something likehttps://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing-P
and changing.*
to.*?
â Michael Mrozekâ¦
Aug 6 at 19:04
add a comment |Â
up vote
0
down vote
EDIT: since the question had some changes since I posted my answer, so did my understanding of it.
If all your rows have the pattern xxxx
, then all you gotta do is a regex replace with sed
. I.e.:
sed 's/xxxx*//g'
If you first need to grep
the rows, then pipe sed
after grep
. I.e.:
grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'
Depending of the real pattern you have, this approach may or may not be of use.
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Try the following regular expression, https://www.instagram.com/p/[^/]+/
#!/bin/bash
data="ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ"
echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'
The magic part is [^/]+/
, it grabs everything up to the next forward slash.
Sample output from the above script.
zb@server ~ $ ./tmp.sh
https://www.instagram.com/p/BRhNDg5jne7/
It works! Thank you!
â Yusuke Otsubo
yesterday
add a comment |Â
up vote
1
down vote
accepted
Try the following regular expression, https://www.instagram.com/p/[^/]+/
#!/bin/bash
data="ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ"
echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'
The magic part is [^/]+/
, it grabs everything up to the next forward slash.
Sample output from the above script.
zb@server ~ $ ./tmp.sh
https://www.instagram.com/p/BRhNDg5jne7/
It works! Thank you!
â Yusuke Otsubo
yesterday
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Try the following regular expression, https://www.instagram.com/p/[^/]+/
#!/bin/bash
data="ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ"
echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'
The magic part is [^/]+/
, it grabs everything up to the next forward slash.
Sample output from the above script.
zb@server ~ $ ./tmp.sh
https://www.instagram.com/p/BRhNDg5jne7/
Try the following regular expression, https://www.instagram.com/p/[^/]+/
#!/bin/bash
data="ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ"
echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'
The magic part is [^/]+/
, it grabs everything up to the next forward slash.
Sample output from the above script.
zb@server ~ $ ./tmp.sh
https://www.instagram.com/p/BRhNDg5jne7/
answered Aug 6 at 16:18
Zachary Brady
3,376831
3,376831
It works! Thank you!
â Yusuke Otsubo
yesterday
add a comment |Â
It works! Thank you!
â Yusuke Otsubo
yesterday
It works! Thank you!
â Yusuke Otsubo
yesterday
It works! Thank you!
â Yusuke Otsubo
yesterday
add a comment |Â
up vote
3
down vote
Using grep :
echo "ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"
output:
https://www.instagram.com/p/BRhNDg5jne7/
add a comment |Â
up vote
3
down vote
Using grep :
echo "ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"
output:
https://www.instagram.com/p/BRhNDg5jne7/
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Using grep :
echo "ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"
output:
https://www.instagram.com/p/BRhNDg5jne7/
Using grep :
echo "ÃÂÃÂÃÂÃÂÃÂÃÂhttps://www.instagram.com/p/BRhNDg5jne7/ÃÂÃÂÃÂÃÂÃÂÃÂÃÂÃÂ" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"
output:
https://www.instagram.com/p/BRhNDg5jne7/
edited Aug 6 at 18:05
answered Aug 6 at 16:37
SivaPrasath
3,68311636
3,68311636
add a comment |Â
add a comment |Â
up vote
0
down vote
no need of perl regex You can try :
grep -o "https://www.instagram.com/.*/"
1
You probably want a non-greedy match, or something likehttps://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing-P
and changing.*
to.*?
â Michael Mrozekâ¦
Aug 6 at 19:04
add a comment |Â
up vote
0
down vote
no need of perl regex You can try :
grep -o "https://www.instagram.com/.*/"
1
You probably want a non-greedy match, or something likehttps://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing-P
and changing.*
to.*?
â Michael Mrozekâ¦
Aug 6 at 19:04
add a comment |Â
up vote
0
down vote
up vote
0
down vote
no need of perl regex You can try :
grep -o "https://www.instagram.com/.*/"
no need of perl regex You can try :
grep -o "https://www.instagram.com/.*/"
answered Aug 6 at 18:08
ctac_
986116
986116
1
You probably want a non-greedy match, or something likehttps://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing-P
and changing.*
to.*?
â Michael Mrozekâ¦
Aug 6 at 19:04
add a comment |Â
1
You probably want a non-greedy match, or something likehttps://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing-P
and changing.*
to.*?
â Michael Mrozekâ¦
Aug 6 at 19:04
1
1
You probably want a non-greedy match, or something like
https://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing -P
and changing .*
to .*?
â Michael Mrozekâ¦
Aug 6 at 19:04
You probably want a non-greedy match, or something like
https://www.instagram.com/foo/ bar baz other stuff/
will match the entire thing. You can do it by passing -P
and changing .*
to .*?
â Michael Mrozekâ¦
Aug 6 at 19:04
add a comment |Â
up vote
0
down vote
EDIT: since the question had some changes since I posted my answer, so did my understanding of it.
If all your rows have the pattern xxxx
, then all you gotta do is a regex replace with sed
. I.e.:
sed 's/xxxx*//g'
If you first need to grep
the rows, then pipe sed
after grep
. I.e.:
grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'
Depending of the real pattern you have, this approach may or may not be of use.
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
add a comment |Â
up vote
0
down vote
EDIT: since the question had some changes since I posted my answer, so did my understanding of it.
If all your rows have the pattern xxxx
, then all you gotta do is a regex replace with sed
. I.e.:
sed 's/xxxx*//g'
If you first need to grep
the rows, then pipe sed
after grep
. I.e.:
grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'
Depending of the real pattern you have, this approach may or may not be of use.
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
add a comment |Â
up vote
0
down vote
up vote
0
down vote
EDIT: since the question had some changes since I posted my answer, so did my understanding of it.
If all your rows have the pattern xxxx
, then all you gotta do is a regex replace with sed
. I.e.:
sed 's/xxxx*//g'
If you first need to grep
the rows, then pipe sed
after grep
. I.e.:
grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'
Depending of the real pattern you have, this approach may or may not be of use.
EDIT: since the question had some changes since I posted my answer, so did my understanding of it.
If all your rows have the pattern xxxx
, then all you gotta do is a regex replace with sed
. I.e.:
sed 's/xxxx*//g'
If you first need to grep
the rows, then pipe sed
after grep
. I.e.:
grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'
Depending of the real pattern you have, this approach may or may not be of use.
edited Aug 6 at 20:48
answered Aug 6 at 16:25
Juanse Albuja
63
63
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
add a comment |Â
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
hope you are removing, instead of printing.
â SivaPrasath
Aug 6 at 17:27
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
@SivaPrasath please see my edited answer.
â Juanse Albuja
Aug 6 at 20:48
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%2f460859%2fgrep-sentence-between-and-including-two-patterns%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