0

I'm trying to put the date an aws user was created into a more user friendly format in a CSV file using this command. I tried:

aws_user_friendly_date=$(date --date "$aws_user_create_date" '+%B %d\\, %Y') aws_user_friendly_date=$(date --date "$aws_user_create_date" '+%B %d\, %Y') 

I want to comment out the comma, so it formats correctly in the CSV file.

But it doesn't work and I get this as the output:

AWS Account Creation Date: June 15\\, 2017 AWS Account Creation Date: June 15\, 2017 

And if I leave the comma so that it's not escaped, the CSV file puts the year into it's own column. How can I show the escape the comma correctly so that it doesn't confuse a CSV file?

1
  • 2
    You don't escape delimiters in a csv, you encapsulate fields containing delimiters; usually with double quotes. So, in your CSV it will look like "AWS Account Creation Date: June 15, 2017" this isn't something your date command needs to worry about though. Instead worry about it when shoving this into your CSV. Commented Nov 6, 2018 at 16:09

1 Answer 1

2

In many CSV dialects, a backslash is just a regular character, and doesn't escape anything. The way to put a literal comma in a field is to wrap the field value with double quotes.

aws_user_friendly_date=$(date --date "$aws_user_create_date" '+"%B %d, %Y"') 

Probably a better design overall would be to store the date in proper machine-readable form, and convert it to human-readable friendly format only when you need to display it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.