Reputation: 55
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 ?
Upvotes: 0
Views: 1587
Reputation: 92854
With single awk process:
awk -v d="1985-09-09" -F'|' '$4 >= d' file
Upvotes: 1