grep: Not a recognized flag: o
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
add a comment |
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
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
The commanduname -s
gives me 'AIX'
– BlueNinja
Dec 4 '18 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 '18 at 9:24
Is yourData
variable a line from the output ofgrep
? If it is, you can probably do whatever you are doing a fair bit more efficiently by runningperl
orawk
over the original log files. Parsing the output ofgrep
is not an ideal solution.
– Kusalananda
Dec 4 '18 at 10:41
add a comment |
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
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
grep variable aix
edited Dec 9 '18 at 14:29
Jeff Schaller
39.2k1054125
39.2k1054125
asked Dec 4 '18 at 9:03
BlueNinjaBlueNinja
213
213
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
The commanduname -s
gives me 'AIX'
– BlueNinja
Dec 4 '18 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 '18 at 9:24
Is yourData
variable a line from the output ofgrep
? If it is, you can probably do whatever you are doing a fair bit more efficiently by runningperl
orawk
over the original log files. Parsing the output ofgrep
is not an ideal solution.
– Kusalananda
Dec 4 '18 at 10:41
add a comment |
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
The commanduname -s
gives me 'AIX'
– BlueNinja
Dec 4 '18 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 '18 at 9:24
Is yourData
variable a line from the output ofgrep
? If it is, you can probably do whatever you are doing a fair bit more efficiently by runningperl
orawk
over the original log files. Parsing the output ofgrep
is not an ideal solution.
– Kusalananda
Dec 4 '18 at 10:41
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
The command
uname -s
gives me 'AIX'– BlueNinja
Dec 4 '18 at 9:21
The command
uname -s
gives me 'AIX'– BlueNinja
Dec 4 '18 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 '18 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 '18 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 '18 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 '18 at 10:41
add a comment |
1 Answer
1
active
oldest
votes
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
1
Note also that the data in theData
variable is a line produced bygrep
. 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 '18 at 10:43
add a comment |
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
});
}
});
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
Required, but never shown
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
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
1
Note also that the data in theData
variable is a line produced bygrep
. 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 '18 at 10:43
add a comment |
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
1
Note also that the data in theData
variable is a line produced bygrep
. 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 '18 at 10:43
add a comment |
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
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
edited Dec 4 '18 at 9:28
answered Dec 4 '18 at 9:20
terdon♦terdon
129k32253428
129k32253428
1
Note also that the data in theData
variable is a line produced bygrep
. 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 '18 at 10:43
add a comment |
1
Note also that the data in theData
variable is a line produced bygrep
. 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 '18 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 '18 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 '18 at 10:43
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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
What operating system are you using?
– terdon♦
Dec 4 '18 at 9:16
The command
uname -s
gives me 'AIX'– BlueNinja
Dec 4 '18 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 '18 at 9:24
Is your
Data
variable a line from the output ofgrep
? If it is, you can probably do whatever you are doing a fair bit more efficiently by runningperl
orawk
over the original log files. Parsing the output ofgrep
is not an ideal solution.– Kusalananda
Dec 4 '18 at 10:41