1

I have a file with dates where i want the dates to change to the day of the week using bash. I did this by the following while statement:

while read p; do
    date -d $p +%A
done <dates.txt

This works fine, but now i want the output of this statement in a file, say output.txt.

I tried

while read p; do
    date -d $p +%A
done <dates.txt >output.txt

But this gives the error date: extra operand '+%A'

2
  • 3
    I guess you want while IFS= read -r p; do date -d "$p" +%A; done > output.txt Commented Mar 3, 2020 at 15:06
  • 2
    Welcome! Are you sure no change was made to dates.txt in-between the code change? Please note double quotes around $p in KamilCuk's suggestion, that's generally important. Commented Mar 3, 2020 at 15:18

1 Answer 1

2

It worked, thanks for the help.

I now have

while IFS= read -r p; do
   date -d "$p" +%A
done <dates.txt >output.txt
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.