2

to pass date and time to the date -d command by reading from file

I tried:

#cat temp.txt
2013/10/31 10:57:02
#cat temp.txt | xargs date -d
date: the argument `10:57:02' lacks a leading `+';
when using an option to specify date(s), any non-option
argument must be a format string beginning with `+'

2 Answers 2

8

You could say:

cat temp.txt | xargs -i date -d {}

or avoid Useless Use of cat,

date -d "$(<temp.txt)"
1
  • 1
    if use timestamp, use this command: cat temp.txt |xargs -i date -d@{}
    – backingwu
    Commented Aug 16, 2016 at 2:32
5

you can use -0 also

$ cat temp.txt | xargs -0 date -d

Useful when input items might contain white space, quote marks, or backslashes.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.