Extract addresses separated by semicolon and print each address in a line
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have a file with the following input. The numbers separated by dots represents addresses. Any number in address can be one or more digits as follows:
[112.112.112.112;3.3.3.3;44.44.44.44]
[6.6.6.6;17.17.17.17;88.88.88.88]
I want to extract each address without the semicolons and brackets (addresses are separated by semicolon ;
), and insert each address in a line in a new file to produce this output:
112.112.112.112
3.3.3.3
44.44.44.44
6.6.6.6
17.17.17.17
88.88.88.88
As a first step, I tried grep to extract the addresses as follows:
grep -E 'd+.d+.d+.d+' myfile.txt > newfile.txt
But it does not print anything.
grep regular-expression string search text-formatting
add a comment |Â
up vote
3
down vote
favorite
I have a file with the following input. The numbers separated by dots represents addresses. Any number in address can be one or more digits as follows:
[112.112.112.112;3.3.3.3;44.44.44.44]
[6.6.6.6;17.17.17.17;88.88.88.88]
I want to extract each address without the semicolons and brackets (addresses are separated by semicolon ;
), and insert each address in a line in a new file to produce this output:
112.112.112.112
3.3.3.3
44.44.44.44
6.6.6.6
17.17.17.17
88.88.88.88
As a first step, I tried grep to extract the addresses as follows:
grep -E 'd+.d+.d+.d+' myfile.txt > newfile.txt
But it does not print anything.
grep regular-expression string search text-formatting
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Thanks. Yes. But that is obvious now to pipe with and sort using:| sort -u
. I will remove it form the questions though.
– user9371654
Aug 28 at 8:01
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a file with the following input. The numbers separated by dots represents addresses. Any number in address can be one or more digits as follows:
[112.112.112.112;3.3.3.3;44.44.44.44]
[6.6.6.6;17.17.17.17;88.88.88.88]
I want to extract each address without the semicolons and brackets (addresses are separated by semicolon ;
), and insert each address in a line in a new file to produce this output:
112.112.112.112
3.3.3.3
44.44.44.44
6.6.6.6
17.17.17.17
88.88.88.88
As a first step, I tried grep to extract the addresses as follows:
grep -E 'd+.d+.d+.d+' myfile.txt > newfile.txt
But it does not print anything.
grep regular-expression string search text-formatting
I have a file with the following input. The numbers separated by dots represents addresses. Any number in address can be one or more digits as follows:
[112.112.112.112;3.3.3.3;44.44.44.44]
[6.6.6.6;17.17.17.17;88.88.88.88]
I want to extract each address without the semicolons and brackets (addresses are separated by semicolon ;
), and insert each address in a line in a new file to produce this output:
112.112.112.112
3.3.3.3
44.44.44.44
6.6.6.6
17.17.17.17
88.88.88.88
As a first step, I tried grep to extract the addresses as follows:
grep -E 'd+.d+.d+.d+' myfile.txt > newfile.txt
But it does not print anything.
grep regular-expression string search text-formatting
edited Aug 28 at 8:02
asked Aug 27 at 9:26


user9371654
1226
1226
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Thanks. Yes. But that is obvious now to pipe with and sort using:| sort -u
. I will remove it form the questions though.
– user9371654
Aug 28 at 8:01
add a comment |Â
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Thanks. Yes. But that is obvious now to pipe with and sort using:| sort -u
. I will remove it form the questions though.
– user9371654
Aug 28 at 8:01
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Thanks. Yes. But that is obvious now to pipe with and sort using:
| sort -u
. I will remove it form the questions though.– user9371654
Aug 28 at 8:01
Thanks. Yes. But that is obvious now to pipe with and sort using:
| sort -u
. I will remove it form the questions though.– user9371654
Aug 28 at 8:01
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
5
down vote
accepted
Extended Regex (-E
or egrep
) does not know about d
. Use -P
as suggested by @Alexander or use -E
with [0-9]
or [[:digit:]]
instead.
Add -o
to select the matches only instead of whole matching lines. This will also break up the single matches into new lines.
grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' myfile.txt
or
grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+' myfile.txt
using Perl Regex (-P
or pgrep
):
grep -Po 'd+.d+.d+.d+' myfile.txt
If you change +
to *
you can also use Basic Regex:
grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]*' myfile.txt
I liked this answer as it expalined what's -o for and why -E does not work. But I will usegrep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?
– user9371654
Aug 27 at 9:41
add a comment |Â
up vote
3
down vote
Replace -E
with -P
and add -o
:
grep -P -o 'd+.d+.d+.d+' myfile.txt
add a comment |Â
up vote
2
down vote
Using awk
:
awk 'NF' RS='[;]' infile
Or with tr
if you don't mind the first empty line:
tr -s '];[' 'n' <infile
add a comment |Â
up vote
0
down vote
grep
is kind of overkill for this task. tr
is sufficient:
$ < input.txt tr -d '' | tr ';' 'n' | sort -u
The sort -u
part removes duplicate addresses.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Extended Regex (-E
or egrep
) does not know about d
. Use -P
as suggested by @Alexander or use -E
with [0-9]
or [[:digit:]]
instead.
Add -o
to select the matches only instead of whole matching lines. This will also break up the single matches into new lines.
grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' myfile.txt
or
grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+' myfile.txt
using Perl Regex (-P
or pgrep
):
grep -Po 'd+.d+.d+.d+' myfile.txt
If you change +
to *
you can also use Basic Regex:
grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]*' myfile.txt
I liked this answer as it expalined what's -o for and why -E does not work. But I will usegrep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?
– user9371654
Aug 27 at 9:41
add a comment |Â
up vote
5
down vote
accepted
Extended Regex (-E
or egrep
) does not know about d
. Use -P
as suggested by @Alexander or use -E
with [0-9]
or [[:digit:]]
instead.
Add -o
to select the matches only instead of whole matching lines. This will also break up the single matches into new lines.
grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' myfile.txt
or
grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+' myfile.txt
using Perl Regex (-P
or pgrep
):
grep -Po 'd+.d+.d+.d+' myfile.txt
If you change +
to *
you can also use Basic Regex:
grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]*' myfile.txt
I liked this answer as it expalined what's -o for and why -E does not work. But I will usegrep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?
– user9371654
Aug 27 at 9:41
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Extended Regex (-E
or egrep
) does not know about d
. Use -P
as suggested by @Alexander or use -E
with [0-9]
or [[:digit:]]
instead.
Add -o
to select the matches only instead of whole matching lines. This will also break up the single matches into new lines.
grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' myfile.txt
or
grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+' myfile.txt
using Perl Regex (-P
or pgrep
):
grep -Po 'd+.d+.d+.d+' myfile.txt
If you change +
to *
you can also use Basic Regex:
grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]*' myfile.txt
Extended Regex (-E
or egrep
) does not know about d
. Use -P
as suggested by @Alexander or use -E
with [0-9]
or [[:digit:]]
instead.
Add -o
to select the matches only instead of whole matching lines. This will also break up the single matches into new lines.
grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' myfile.txt
or
grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+' myfile.txt
using Perl Regex (-P
or pgrep
):
grep -Po 'd+.d+.d+.d+' myfile.txt
If you change +
to *
you can also use Basic Regex:
grep -o '[0-9]*.[0-9]*.[0-9]*.[0-9]*' myfile.txt
edited Aug 27 at 11:41
answered Aug 27 at 9:33
RoVo
1,234210
1,234210
I liked this answer as it expalined what's -o for and why -E does not work. But I will usegrep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?
– user9371654
Aug 27 at 9:41
add a comment |Â
I liked this answer as it expalined what's -o for and why -E does not work. But I will usegrep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?
– user9371654
Aug 27 at 9:41
I liked this answer as it expalined what's -o for and why -E does not work. But I will use
grep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?– user9371654
Aug 27 at 9:41
I liked this answer as it expalined what's -o for and why -E does not work. But I will use
grep -P -o 'd+.d+.d+.d+' myfile.txt
as it is more readable. So can you add it so I accept the answer please?– user9371654
Aug 27 at 9:41
add a comment |Â
up vote
3
down vote
Replace -E
with -P
and add -o
:
grep -P -o 'd+.d+.d+.d+' myfile.txt
add a comment |Â
up vote
3
down vote
Replace -E
with -P
and add -o
:
grep -P -o 'd+.d+.d+.d+' myfile.txt
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Replace -E
with -P
and add -o
:
grep -P -o 'd+.d+.d+.d+' myfile.txt
Replace -E
with -P
and add -o
:
grep -P -o 'd+.d+.d+.d+' myfile.txt
edited Aug 27 at 9:55
GAD3R
22.7k154895
22.7k154895
answered Aug 27 at 9:30
Alexander
65012
65012
add a comment |Â
add a comment |Â
up vote
2
down vote
Using awk
:
awk 'NF' RS='[;]' infile
Or with tr
if you don't mind the first empty line:
tr -s '];[' 'n' <infile
add a comment |Â
up vote
2
down vote
Using awk
:
awk 'NF' RS='[;]' infile
Or with tr
if you don't mind the first empty line:
tr -s '];[' 'n' <infile
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Using awk
:
awk 'NF' RS='[;]' infile
Or with tr
if you don't mind the first empty line:
tr -s '];[' 'n' <infile
Using awk
:
awk 'NF' RS='[;]' infile
Or with tr
if you don't mind the first empty line:
tr -s '];[' 'n' <infile
edited Aug 27 at 14:13
answered Aug 27 at 9:30
αғsýιη
15.6k92563
15.6k92563
add a comment |Â
add a comment |Â
up vote
0
down vote
grep
is kind of overkill for this task. tr
is sufficient:
$ < input.txt tr -d '' | tr ';' 'n' | sort -u
The sort -u
part removes duplicate addresses.
add a comment |Â
up vote
0
down vote
grep
is kind of overkill for this task. tr
is sufficient:
$ < input.txt tr -d '' | tr ';' 'n' | sort -u
The sort -u
part removes duplicate addresses.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
grep
is kind of overkill for this task. tr
is sufficient:
$ < input.txt tr -d '' | tr ';' 'n' | sort -u
The sort -u
part removes duplicate addresses.
grep
is kind of overkill for this task. tr
is sufficient:
$ < input.txt tr -d '' | tr ';' 'n' | sort -u
The sort -u
part removes duplicate addresses.
answered Aug 27 at 18:50
maxschlepzig
32k30135202
32k30135202
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%2f465028%2fextract-addresses-separated-by-semicolon-and-print-each-address-in-a-line%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
Should 'output to contains only unique umbers and no duplicates' read 'output to contain only unique addresses (i.e. no duplicates)'?
– maxschlepzig
Aug 27 at 18:52
Thanks. Yes. But that is obvious now to pipe with and sort using:
| sort -u
. I will remove it form the questions though.– user9371654
Aug 28 at 8:01