0

Hello I'm trying to make a script to search for specific info from a file and print it. My case is this : I have a file in the format of : id|lastname|firstname|birthday| . I want to call the script and given a date argument and the file to make it show me all the "people" born after the date I've given. Let me show you my code :

#!/bin/bash case $1 in --born-since ) d=($2 +%F); # this one puts the date I've given into the variable d grep -vE '^#' $4 | awk -F "|" ' $4 >= $d ' ;; esac 

I call this script in the form of :

./script --born-since <date> -f <file> 

Point is it's not doing what I want it to do. I prints wrong results. For example in a file with 4 dates ( 1989-12-03,1984-02-18,1988-10-14,1980-02-02), given the date of 1985-05-13 it prints only the person with date 1984-02-18 which is incorrect. It's probably comparing something else and not the date. Any advice ?

2
  • yeah my bad,it's wrong, it's just too many different results from different entries, therefore I got a bit confused, editing Commented Oct 14, 2017 at 17:38
  • post a few input lines will all fields Commented Oct 14, 2017 at 17:39

1 Answer 1

1

With single awk process:

awk -v d="1985-09-09" -F'|' '$4 >= d' file 
Sign up to request clarification or add additional context in comments.

2 Comments

This works, although for dates equal it doesn't. Thank you though since I can try and experiment around that! Is it possible to compare for greater and less (for 2 different dates of course) in a single command?)
@DimitrisDelis, yes, it's possible

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.