I'm building a list of aws users with this command:
Code:
aws iam get-user --user-name "$aws_user_name" --profile="$aws_key"
If the user doesn't exist you get this output:
Code:
aws iam get-user --user-name fred --profile=lab
An error occurred (NoSuchEntity) when calling the GetUser operation: The user with name fred cannot be found.
I can suppress that error on the user output with this command, but a new error appears:
Code:
aws iam get-user --user-name fred --profile=lab 2>&1 | sed 's/^An error occurred (NoSuchEntity)\.*//g' | jq -r '.User.UserName'
parse error: Invalid numeric literal at line 2, column 6
I try to remove the parse error with the next line, but it doesn't work
Code:
aws iam get-user --user-name fred --profile=lab 2>&1 | sed 's/^An error occurred (NoSuchEntity)\.*//g' | sed 's/parse\ error\.*//g' | jq -r '.User.UserName'
parse error: Invalid numeric literal at line 2, column 6
How can I get rid of the parse error from the user output?
I'm writing the same line to a log file with the error intact for later analysis. But I don't want the user to see these errors.