"Khushboo Soni" wrote:
> I'm trying to solve Q3 in Exercise 2. As you may know that we have some lines of text
> in Feb2019 weather data. My first question is do we use TAIL/HEAD command to remove
> some rows or is there some other command to do that. I thought we could use CUT
> command for chopping rows but I haven't yet found the specific option to do so.
Keep in mind that cut performs a vertical cut - it just saves the required (vertical)
columns that we want. cut cannot be used to request which (horizontal) lines we want.
Instead, we can use grep to select just the (horizontal) rows that we want.
All of the rows that we want need to have a common pattern, and that pattern should not be
in any of the lines we don't want.
> At the moment I'm using tail -28 for Feb2019 and tail -29 for Feb2020 but may be
> there is a better way to do this.
Those solutions will probably work, but they are not very general.
For example you had to know if a year was a leap year, and then use the exact number of days
Moreover, if the questions asked about January, it would be neither 28 or 29.
Instead, can you find a pattern common to all of the required lines,
and then use grep to select just thos elines?
> Also do we have to calculate average of the column to determine which month is
> hotter/wetter or are we just comparing?
Actually I should have marked that last part (your question) as 'super hard', at this stage.
If you know how to perform some calculations on the numbers in columns, then you could
already do that, but it is harder. Possible tools to use may be awk, dc, or even python,
but don't put too much effort into it at this stage!