grep: Not a recognized flag: o












3














I am trying to extract the date and timestamps from my log file string ($Data in the below code) on AIX using a regex and loading it into a text file as below:



Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
echo "$data" | grep -o -n '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]' > timestamps.txt


I get the below error most probably due to the unix version in my host being too old and it doesn't recognize the -o option. Is there any alternative method in which I can get the functionality of -o done?



grep: Not a recognized flag: o
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] pattern_list [file...]









share|improve this question
























  • What operating system are you using?
    – terdon
    Dec 4 at 9:16










  • The command uname -s gives me 'AIX'
    – BlueNinja
    Dec 4 at 9:21






  • 1




    It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
    – Kusalananda
    Dec 4 at 9:24










  • Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
    – Kusalananda
    Dec 4 at 10:41


















3














I am trying to extract the date and timestamps from my log file string ($Data in the below code) on AIX using a regex and loading it into a text file as below:



Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
echo "$data" | grep -o -n '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]' > timestamps.txt


I get the below error most probably due to the unix version in my host being too old and it doesn't recognize the -o option. Is there any alternative method in which I can get the functionality of -o done?



grep: Not a recognized flag: o
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] pattern_list [file...]









share|improve this question
























  • What operating system are you using?
    – terdon
    Dec 4 at 9:16










  • The command uname -s gives me 'AIX'
    – BlueNinja
    Dec 4 at 9:21






  • 1




    It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
    – Kusalananda
    Dec 4 at 9:24










  • Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
    – Kusalananda
    Dec 4 at 10:41
















3












3








3







I am trying to extract the date and timestamps from my log file string ($Data in the below code) on AIX using a regex and loading it into a text file as below:



Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
echo "$data" | grep -o -n '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]' > timestamps.txt


I get the below error most probably due to the unix version in my host being too old and it doesn't recognize the -o option. Is there any alternative method in which I can get the functionality of -o done?



grep: Not a recognized flag: o
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] pattern_list [file...]









share|improve this question















I am trying to extract the date and timestamps from my log file string ($Data in the below code) on AIX using a regex and loading it into a text file as below:



Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
echo "$data" | grep -o -n '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]' > timestamps.txt


I get the below error most probably due to the unix version in my host being too old and it doesn't recognize the -o option. Is there any alternative method in which I can get the functionality of -o done?



grep: Not a recognized flag: o
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] pattern_list [file...]






grep variable aix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 at 14:29









Jeff Schaller

38.6k1053125




38.6k1053125










asked Dec 4 at 9:03









BlueNinja

213




213












  • What operating system are you using?
    – terdon
    Dec 4 at 9:16










  • The command uname -s gives me 'AIX'
    – BlueNinja
    Dec 4 at 9:21






  • 1




    It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
    – Kusalananda
    Dec 4 at 9:24










  • Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
    – Kusalananda
    Dec 4 at 10:41




















  • What operating system are you using?
    – terdon
    Dec 4 at 9:16










  • The command uname -s gives me 'AIX'
    – BlueNinja
    Dec 4 at 9:21






  • 1




    It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
    – Kusalananda
    Dec 4 at 9:24










  • Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
    – Kusalananda
    Dec 4 at 10:41


















What operating system are you using?
– terdon
Dec 4 at 9:16




What operating system are you using?
– terdon
Dec 4 at 9:16












The command uname -s gives me 'AIX'
– BlueNinja
Dec 4 at 9:21




The command uname -s gives me 'AIX'
– BlueNinja
Dec 4 at 9:21




1




1




It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
– Kusalananda
Dec 4 at 9:24




It's not that your Unix is "too old", it's that you are relying on non-standard functionality.
– Kusalananda
Dec 4 at 9:24












Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
– Kusalananda
Dec 4 at 10:41






Is your Data variable a line from the output of grep? If it is, you can probably do whatever you are doing a fair bit more efficiently by running perl or awk over the original log files. Parsing the output of grep is not an ideal solution.
– Kusalananda
Dec 4 at 10:41












1 Answer
1






active

oldest

votes


















4














Note that your regex wouldn't work even if -o was recognized by your grep implementation. You also need -E to enable extended regular expressions. Assuming you have perl, which you probably do, you can try:



$ Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
$ echo "$Data" | perl -lne '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/ && print "$.:$&"'
1:2018-12-03 00:00


But do you really need to make your regex that complicated? Isn't this enough?



$ echo "$Data" | perl -lne '/d{4}-d{2}-d{2} d{2}:d{2}/ && print "$.:$&"'
1:2018-12-03 00:00





share|improve this answer



















  • 1




    Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
    – Kusalananda
    Dec 4 at 10:43













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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
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%2f485850%2fgrep-not-a-recognized-flag-o%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Note that your regex wouldn't work even if -o was recognized by your grep implementation. You also need -E to enable extended regular expressions. Assuming you have perl, which you probably do, you can try:



$ Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
$ echo "$Data" | perl -lne '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/ && print "$.:$&"'
1:2018-12-03 00:00


But do you really need to make your regex that complicated? Isn't this enough?



$ echo "$Data" | perl -lne '/d{4}-d{2}-d{2} d{2}:d{2}/ && print "$.:$&"'
1:2018-12-03 00:00





share|improve this answer



















  • 1




    Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
    – Kusalananda
    Dec 4 at 10:43


















4














Note that your regex wouldn't work even if -o was recognized by your grep implementation. You also need -E to enable extended regular expressions. Assuming you have perl, which you probably do, you can try:



$ Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
$ echo "$Data" | perl -lne '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/ && print "$.:$&"'
1:2018-12-03 00:00


But do you really need to make your regex that complicated? Isn't this enough?



$ echo "$Data" | perl -lne '/d{4}-d{2}-d{2} d{2}:d{2}/ && print "$.:$&"'
1:2018-12-03 00:00





share|improve this answer



















  • 1




    Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
    – Kusalananda
    Dec 4 at 10:43
















4












4








4






Note that your regex wouldn't work even if -o was recognized by your grep implementation. You also need -E to enable extended regular expressions. Assuming you have perl, which you probably do, you can try:



$ Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
$ echo "$Data" | perl -lne '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/ && print "$.:$&"'
1:2018-12-03 00:00


But do you really need to make your regex that complicated? Isn't this enough?



$ echo "$Data" | perl -lne '/d{4}-d{2}-d{2} d{2}:d{2}/ && print "$.:$&"'
1:2018-12-03 00:00





share|improve this answer














Note that your regex wouldn't work even if -o was recognized by your grep implementation. You also need -E to enable extended regular expressions. Assuming you have perl, which you probably do, you can try:



$ Data="Logs/2018-12-03/log.txt:3:2018-12-03 00:00:04,333 452621453 [blah blah blah"
$ echo "$Data" | perl -lne '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/ && print "$.:$&"'
1:2018-12-03 00:00


But do you really need to make your regex that complicated? Isn't this enough?



$ echo "$Data" | perl -lne '/d{4}-d{2}-d{2} d{2}:d{2}/ && print "$.:$&"'
1:2018-12-03 00:00






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 4 at 9:28

























answered Dec 4 at 9:20









terdon

128k31247423




128k31247423








  • 1




    Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
    – Kusalananda
    Dec 4 at 10:43
















  • 1




    Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
    – Kusalananda
    Dec 4 at 10:43










1




1




Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
– Kusalananda
Dec 4 at 10:43






Note also that the data in the Data variable is a line produced by grep. This makes me think that the user is first running a grep of some kind to get the lines they want, and then iterating in a shell loop over these lines. This is quite an suboptimal approach to log file parsing.
– Kusalananda
Dec 4 at 10:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485850%2fgrep-not-a-recognized-flag-o%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар