How to filter lines with the same date in different formats

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question


















  • 1




    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










  • @RomanPerekhrest I corrected the typo (it was 201710)
    – Arianna Angeletti
    Oct 16 '17 at 13:37














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?







share|improve this question


















  • 1




    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










  • @RomanPerekhrest I corrected the typo (it was 201710)
    – Arianna Angeletti
    Oct 16 '17 at 13:37












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?







share|improve this question














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?









share|improve this question













share|improve this question




share|improve this question








edited Oct 16 '17 at 13:36

























asked Oct 16 '17 at 12:14









Arianna Angeletti

1154




1154







  • 1




    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










  • @RomanPerekhrest I corrected the typo (it was 201710)
    – Arianna Angeletti
    Oct 16 '17 at 13:37












  • 1




    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










  • @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










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





share|improve this answer




















  • 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


















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





share|improve this answer




















  • ++ 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




    @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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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





share|improve this answer




















  • 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















up vote
3
down vote



accepted










One way to do it:



grep -E '/([0-9]6).([0-9]2).* TAG12' file





share|improve this answer




















  • 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













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





share|improve this answer












One way to do it:



grep -E '/([0-9]6).([0-9]2).* TAG12' file






share|improve this answer












share|improve this answer



share|improve this answer










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 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
















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













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





share|improve this answer




















  • ++ 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




    @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














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





share|improve this answer




















  • ++ 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




    @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












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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 16 '17 at 12:31









RomanPerekhrest

22.5k12145




22.5k12145











  • ++ 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




    @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






  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)