How to filter lines with the same date in different formats

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a txt file like this:
./201709.15.txt:88:word word TAG201709152000 word word
./201709.19.txt:3:word TAG201709152000 word word
./201710.10.txt:5:word word TAG201709152000 word word word
and I need to filter only the lines as:
./201709.15.txt:88:word word TAG201709152000 word word
(i.e. with the same date at the beginning: ./YYYMM.dd.txt and after TAG: TAGYYYYMMddhhmm)
Is it possible with shell script?
shell-script text-processing date
add a comment |Â
up vote
0
down vote
favorite
I have a txt file like this:
./201709.15.txt:88:word word TAG201709152000 word word
./201709.19.txt:3:word TAG201709152000 word word
./201710.10.txt:5:word word TAG201709152000 word word word
and I need to filter only the lines as:
./201709.15.txt:88:word word TAG201709152000 word word
(i.e. with the same date at the beginning: ./YYYMM.dd.txt and after TAG: TAGYYYYMMddhhmm)
Is it possible with shell script?
shell-script text-processing date
1
the 3rd item2017010does not correspondYYYMM. typo?
â RomanPerekhrest
Oct 16 '17 at 12:24
Even if the last line in your example./2017010.10would be correct, it'd be a different date. What part do you want to be matched?
â Valentin B
Oct 16 '17 at 12:31
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a txt file like this:
./201709.15.txt:88:word word TAG201709152000 word word
./201709.19.txt:3:word TAG201709152000 word word
./201710.10.txt:5:word word TAG201709152000 word word word
and I need to filter only the lines as:
./201709.15.txt:88:word word TAG201709152000 word word
(i.e. with the same date at the beginning: ./YYYMM.dd.txt and after TAG: TAGYYYYMMddhhmm)
Is it possible with shell script?
shell-script text-processing date
I have a txt file like this:
./201709.15.txt:88:word word TAG201709152000 word word
./201709.19.txt:3:word TAG201709152000 word word
./201710.10.txt:5:word word TAG201709152000 word word word
and I need to filter only the lines as:
./201709.15.txt:88:word word TAG201709152000 word word
(i.e. with the same date at the beginning: ./YYYMM.dd.txt and after TAG: TAGYYYYMMddhhmm)
Is it possible with shell script?
shell-script text-processing date
edited Oct 16 '17 at 13:36
asked Oct 16 '17 at 12:14
Arianna Angeletti
1154
1154
1
the 3rd item2017010does not correspondYYYMM. typo?
â RomanPerekhrest
Oct 16 '17 at 12:24
Even if the last line in your example./2017010.10would be correct, it'd be a different date. What part do you want to be matched?
â Valentin B
Oct 16 '17 at 12:31
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37
add a comment |Â
1
the 3rd item2017010does not correspondYYYMM. typo?
â RomanPerekhrest
Oct 16 '17 at 12:24
Even if the last line in your example./2017010.10would be correct, it'd be a different date. What part do you want to be matched?
â Valentin B
Oct 16 '17 at 12:31
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37
1
1
the 3rd item
2017010 does not correspond YYYMM. typo?â RomanPerekhrest
Oct 16 '17 at 12:24
the 3rd item
2017010 does not correspond YYYMM. typo?â RomanPerekhrest
Oct 16 '17 at 12:24
Even if the last line in your example
./2017010.10 would be correct, it'd be a different date. What part do you want to be matched?â Valentin B
Oct 16 '17 at 12:31
Even if the last line in your example
./2017010.10 would be correct, it'd be a different date. What part do you want to be matched?â Valentin B
Oct 16 '17 at 12:31
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
One way to do it:
grep -E '/([0-9]6).([0-9]2).* TAG12' file
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions ofgrep. Usegrep '/([0-9]6).([0-9]2).* TAG12' fileinstead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?
â Philippos
Oct 16 '17 at 14:23
add a comment |Â
up vote
2
down vote
Awk solution:
awk -F'.' 'match($4,/TAG[0-9]8/) && substr($4,RSTART+3,RLENGTH-3) == substr($2$3,2)' file
The output:
./201709.15.txt:88:word word TAG201709152000 word word
++NiceAwkusage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is needed
â Inian
Oct 16 '17 at 12:38
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
One way to do it:
grep -E '/([0-9]6).([0-9]2).* TAG12' file
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions ofgrep. Usegrep '/([0-9]6).([0-9]2).* TAG12' fileinstead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?
â Philippos
Oct 16 '17 at 14:23
add a comment |Â
up vote
3
down vote
accepted
One way to do it:
grep -E '/([0-9]6).([0-9]2).* TAG12' file
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions ofgrep. Usegrep '/([0-9]6).([0-9]2).* TAG12' fileinstead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?
â Philippos
Oct 16 '17 at 14:23
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
One way to do it:
grep -E '/([0-9]6).([0-9]2).* TAG12' file
One way to do it:
grep -E '/([0-9]6).([0-9]2).* TAG12' file
answered Oct 16 '17 at 12:28
Satà  Katsura
10.7k11533
10.7k11533
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions ofgrep. Usegrep '/([0-9]6).([0-9]2).* TAG12' fileinstead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?
â Philippos
Oct 16 '17 at 14:23
add a comment |Â
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions ofgrep. Usegrep '/([0-9]6).([0-9]2).* TAG12' fileinstead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?
â Philippos
Oct 16 '17 at 14:23
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions of
grep. Use grep '/([0-9]6).([0-9]2).* TAG12' file instead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?â Philippos
Oct 16 '17 at 14:23
Good solution. Two remarks: 1) Backreferences are not required by the extended regular expressions standard , so this may not work with all versions of
grep. Use grep '/([0-9]6).([0-9]2).* TAG12' file instead (although it's less readable). 2) Are you sure that @Arianna will understand this without an explanation?â Philippos
Oct 16 '17 at 14:23
add a comment |Â
up vote
2
down vote
Awk solution:
awk -F'.' 'match($4,/TAG[0-9]8/) && substr($4,RSTART+3,RLENGTH-3) == substr($2$3,2)' file
The output:
./201709.15.txt:88:word word TAG201709152000 word word
++NiceAwkusage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is needed
â Inian
Oct 16 '17 at 12:38
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
add a comment |Â
up vote
2
down vote
Awk solution:
awk -F'.' 'match($4,/TAG[0-9]8/) && substr($4,RSTART+3,RLENGTH-3) == substr($2$3,2)' file
The output:
./201709.15.txt:88:word word TAG201709152000 word word
++NiceAwkusage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is needed
â Inian
Oct 16 '17 at 12:38
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Awk solution:
awk -F'.' 'match($4,/TAG[0-9]8/) && substr($4,RSTART+3,RLENGTH-3) == substr($2$3,2)' file
The output:
./201709.15.txt:88:word word TAG201709152000 word word
Awk solution:
awk -F'.' 'match($4,/TAG[0-9]8/) && substr($4,RSTART+3,RLENGTH-3) == substr($2$3,2)' file
The output:
./201709.15.txt:88:word word TAG201709152000 word word
answered Oct 16 '17 at 12:31
RomanPerekhrest
22.5k12145
22.5k12145
++NiceAwkusage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is needed
â Inian
Oct 16 '17 at 12:38
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
add a comment |Â
++NiceAwkusage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is needed
â Inian
Oct 16 '17 at 12:38
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
++ Nice Awk usage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is neededâ Inian
Oct 16 '17 at 12:38
++ Nice Awk usage, but am curious to know if the OP needs to change the way the o/p is pushed (or) this much complex processing is neededâ Inian
Oct 16 '17 at 12:38
1
1
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
@Inian, you know how it goes: If we don't have enough details - we rely on the current input and the current expected result
â RomanPerekhrest
Oct 16 '17 at 12:44
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%2f398393%2fhow-to-filter-lines-with-the-same-date-in-different-formats%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
1
the 3rd item
2017010does not correspondYYYMM. typo?â RomanPerekhrest
Oct 16 '17 at 12:24
Even if the last line in your example
./2017010.10would be correct, it'd be a different date. What part do you want to be matched?â Valentin B
Oct 16 '17 at 12:31
@RomanPerekhrest I corrected the typo (it was 201710)
â Arianna Angeletti
Oct 16 '17 at 13:37