3

I'm reading in a log file checking for the log chronological sequence. I'm reading the log file into an array, only storing correctly formatted timestamp log lines:

MESSAGE_ONE is the line read from the file.

Timestamp1=$(echo "$MESSAGE_ONE" | cut -c1-20)
Timestamp1date=$(date -d "$Timestamp1" +%s) This line produces an error for incorrectly formatted lines

I handle the error as follows:

if [ "$?" = "1" ]; then
continue
else
Add the valid log line into the array

It works the way I want it to; all I want to do is suppress the error produced by badly formatted log entries. I've tried

Timestamp1date=$(date -d "$Timestamp1" +%s) 2>/dev/null

but it didn't work. I don't want to suppress all errors output by using 2>/dev/null after the cli command. Can someone help please?

1 Answer 1

5

Redirection should be inside the sub shell, so use:

Timestamp1date=$(date -d "$Timestamp1" '+%s' 2>/dev/null)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.