Remove Error From Output Using Sed in Bash
I'm building a list of aws users with this command:
Code:
aws iam get-user --user-name "$aws_user_name" --profile="$aws_key" Code:
aws iam get-user --user-name fred --profile=lab Code:
aws iam get-user --user-name fred --profile=lab 2>&1 | sed 's/^An error occurred (NoSuchEntity)\.*//g' | jq -r '.User.UserName' 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' 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. |
I think you want to be more simple than global search-replace.
I wasn't totally sure, so looked up "sed delete line" https://stackoverflow.com/questions/...pecific-string So you might do something more like: Code:
sed 'An error occurred/d' |
Try changing
Code:
jq -r '.User.UserName' Code:
jq -r '.User?.UserName?' By adding the question marks jq won't complain if either of those keys don't exist. |
Quote:
Code:
aws ... 2>/var/tmp/aws.err By the way, the \.* part of your sed string means “any number of dots” and is probably irrelevant. |
All times are GMT -5. The time now is 11:05 PM. |