0

i need to use variable in instead of direct date.

cat file | awk -F, '{ if ($1>"2012-08-20 11:30" && $1<"2012-08-22 16:00") print }'

thanks in advance

5
  • Then why don't you use a variable? Commented Feb 19, 2018 at 12:51
  • i tried to use i got errors. i don't know how to use that. Commented Feb 19, 2018 at 12:53
  • What is in file? What is the expected output? What variable? What is in variable? Commented Feb 19, 2018 at 12:55
  • i am getting date from command line arguments and use that arguments as input for this command. Commented Feb 19, 2018 at 13:00
  • ex: cat file | awk -F, '{ if ($1>"$date1" && $1<"$date2") print }' Commented Feb 19, 2018 at 13:01

1 Answer 1

2

Based on your shown code, could you please try following and let me know if this helps you.(In lack of samples I haven't tested it)

awk -v date1="2012-08-20 11:30" -v date2="2012-08-22 16:00" -F, '($1>date1 && $1<date2)'  Input_file

In case your variables are coming from shell to awk then following could help you on same, you could change date subtraction order as per your need too:

date1="2012-08-20 11:30"
date2="2012-08-22 16:00"
awk -v date_1="$date1" -v date_2="$date2" -F, '($1>date_1 && $1<date_2)'  Input_file
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.