Unix Data Manipulation/Dispalying File Contents

From Wikiversity
Jump to navigation Jump to search

Displaying file contents[edit | edit source]

Check the contents of your files with less or head. This will give you a clue to their format. We will start with a comma delimited file called results.csv. Each line has the following structure

Surname, Maths_score, English_score, History_score

There are four fields separated by commas. This is a very common file type and easy to work with, but it has a disadvantage - you may have text fields that contain commas as data. In those cases it is easiest to use another character as a field delimiter when you create the data (you may be able to do this for example with Excel - if you cannot you may have to do some clever data munging).

When we view the file with less we see

ADAMS,55,63,65

ALI,52,46,35

BAGAL,51,58,55

BENJAMIN,59,70,68

BLAKEMORE,56,38,40

BUCHAN,45,62,59

CHULANI,63,69,69

CLARK,52,64,65

DALE,50,55,52

DE SOUZA,44,60,62

DENCIK,57,67,65

DOBLE,64,56,65

DRURY,50,50,49

EL-DANA,62,59,60

FREEMAN,52,58,62

FROGGATT,39,57,59

GEORGARA,56,52,50

JAN,62,63,59

JENNER,56,67,65

JUNCO,48,57,55

LEFKARITIS,53,56,59

LUKKA,58,59,55

MILNER,53,62,58

MIYAJI,58,66,60

NICHOLSON,55,55,58

PATEL,60,59,54

PEIRIS,60,52,55

RAMANI,42,43,40

ROSEN,54,55,54

ROWLANDS,47,50,48


 

What command displays the first five lines of a file?