Monday 15 September 2014

shell - Get lines from a specific date afterwards/backwards -


I am working on a shell script. I should get the lines that contain the old information from or from that day. Each line in the file is a record and the first line is old, the last is the latest file contains:

some information \ t date \ t other information

If I fix the given date only, then I think what I am looking for but only that will be the presence of that date in the file. I get the last chance and get the lines from the beginning of the file. I tried awk, but I was completely unsuccessful. This should give me every line that is on or before that date. My failure and last attempt:

awk '$ 1 & lt; = "2015/03/17" '

So I need something like this, gives me all the lines with the date of 2015/03/15 or older, It has to be disturbed and 2 dates have to be compared, according to it's old?

should be very easy because the date format you use should be compared to the letter ..

file: test.txt

  one 2015/03/17 BC 2015-03-12 to 04/04/02/10 FG 2016/01  

Awk command:

  awk -vd = "2015/03 / 15" '{if ($ 2 & lt; = d) {Print $ 0}} 'test.txt  

Just change the date value D = you want.


No comments:

Post a Comment