0

Command 1: echo "11-FEB-19 06.14.52.352000000 AM" | cut -d' ' -f1,2 | sed 's/\./:/g' |cut -d: -f1-3

Command 2: date -d "OUTPUT COMMAND1" +'%s'

Expected : - echo "11-FEB-19 06.14.52.352000000 AM" | cut -d' ' -f1,2 | sed 's/\./:/g' |cut -d: -f1-3 | date -d "XXX" +'%s'

I need output of prev command (cut -d: -f1-3) and put it in XXX

  • 1
    Hello and welcome to the U&L stack exchange site! Please review the Help Center to get information on how to best post to this site. To get to your question, please edit your post to include additional context. Could you clarify what is failing to occur or at least provide additional details to your question as to what is not working? Another point to help your post, would be to please format your code. Thank you! – kemotep Feb 11 at 21:58
  • I need output of prev command (cut -d: -f1-3) and put it in XXX. – Sonal Feb 11 at 22:03
  • I'm not sure what "XXX" refers to. If "XXX" is the formatted date and you want to convert that to the number of seconds since the Unix epoch then your answer is 1549924211 (echo "11-FEB-19 06.14.52.352000000 AM" | cut -d' ' -f1,2 | sed 's/\./:/g' | cut -d: -f1-3 | date +"%s") – rkhff Feb 11 at 22:33
  • If i do date -d "11-FEB-19 06:14:52" +'%s' the output is 1549894492 ... if i execute your command it generates new number every time – Sonal Feb 11 at 22:36
2

A pipeline cmd1 | cmd2 sends the output of the first command to the standard input of the second. What you seem to want is to put the output of the first command on the command line of the second. The way to do that is the command substitution: $(command).

This would put the output of cmd1 on the command line of cmd2:

cmd1 "$(cmd2)"

Or, in your case:

date -d "$(echo ... |cut)" +%s 
0

For readability, I'd still use multiple lines:

datetime=$( echo "11-FEB-19 06.14.52.352000000 AM" | sed -e 's/\./:/g' -e 's/:[^:]\+$//' )
epoch=$( date -d "$datetime" +%s )
echo "$epoch"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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