Can you edit my _AWK_ shell script?

April 24, 2011 at 07:48:13
Specs: Windows Vista
in this text file (class.txt) of the follong format

Surname, Forename: Day.Month.Year: Degree
Sellen, Jo: 03.07.1986: MSc CSE
Parfitt, Harry: 20.03.1984: MSc IT

Help me to modify this shell script which uses AWK to read the file (class.txt)

awk '{gsub(/ +/,"\t");print}' class.txt

and output the data in the tabbed format as shown:

Surname Forename MSc stream Date of Birth
Sellen Jo MSc CSE 03.07.1986
Parfitt Harry MSc IT 20.03.1984

* don't worry if tabbed columns don't line up.

cheerz


See More: Can you edit my _AWK_ shell script?

Report •

#1
April 25, 2011 at 09:30:18
I am assuming that colums 4 and 5 are always the degree:

#!/bin/ksh

awk ' BEGIN { print "Surname Forename MSc stream Date of Birth" }
{
if(NR == 1) # skip the first line
   continue

gsub(":","") # remove the colon
gsub(",","") # remove the comma
printf("%s %s %s %s %s\n", $1, $2, $4, $5, $3)

} ' datafile.txt


Report •
Related Solutions


Ask Question