I have text file with six years (2011-2016) of data. I want to extract only April and May data of all six years.
@STATION_ID,LATITUDE,LONGITUDE,TIME(GMT),DATE(GMT),AIR_TEMP(°C)
IMDE1611_14164B(PITAMPURA),28.7,77.15,0,08/09/2011,33.5
IMDE1611_14164B(PITAMPURA),28.7,77.15,1,08/09/2011,33.3
IMDE1611_14164B(PITAMPURA),28.7,77.15,2,08/09/2011,33.8
IMDE1611_14164B(PITAMPURA),28.7,77.15,3,08/09/2011,33.8
IMDE1611_14164B(PITAMPURA),28.7,77.15,4,08/09/2011,34.5
IMDE1611_14164B(PITAMPURA),28.7,77.15,5,08/09/2011,35.0
IMDE1611_14164B(PITAMPURA),28.7,77.15,6,08/09/2011,34.9
IMDE1611_14164B(PITAMPURA),28.7,77.15,7,08/09/2011,35.4
I am using grep
and sed
commands to filter the data but it is not showing the result I want.
I am using these commands:
grep "??-0[4-5]-????" filename.txt > filename.csv
sed -n '/2016-04-01/,/2016-04-30/{/2016-04-30/d; p}' my_delhi.txt
sed -n '/2016-04-01/,/2016-04-30/p' my_delhi.txt
Best Answer
You can use something else instead of
/
assed
's delimiter.or with regex and '#' as delimiter:
for April and May only (dd/mm/yyyy):
or (mm/dd/yyy):