linux - filter a content file to table -


this input have generated , displays versions of courses both jany , marco @ different times .

on 10:00 course of jany 1 : course:theory:nothing course:applicaton:onehour  on 10:00 course of jany 2 : course:theory:math course:applicaton:twohour  on 10:00 course of marco 1 : course:theory:geo course:applicaton:halfhour  on 10:00 course of marco 2 : course:theory:history course:applicaton:nothing  on 14:00 course of jany 1 : course:theory:nothing course:applicaton:twohours  on 14:00 course of jany 2 : course:theory:music course:applicaton:twohours  on 14:00 course of marco 1 : course:theory:programmation course:applicaton:onehours  on 14:00 course of marco 2 : course:theory:philosophy course:applicaton:nothing 

using awk commands succeeded sort :

awk -f '[\ :]' '/the course of/{h=$2;m=$3} /theory/{print " "h":"m" theory:"$3}' f.txt awk -f '[\ :]' '/the course of/{h=$2;m=$3} /application/{print " "h":"m" application :"$3}' f.txt 
10:00 theory:nothing 14:00 theory:nothing  10:00 application:onehour 14:00 application:twohours 

now improve filter adding names( jany,marco) , versions(1 or 2) shown below .

jany 1,10:00,14:00 theory,nothing,nothing application,onehour,twohour  jany 2,10:00,14:00 theory,math,music application,twohour,twohour  marco 1,10:00,14:00 theory,geo,programmation application,halfhour,onehour  marco 2,10:00,14:00 theory,history,philosoohy application,nothing,nothing 

i stuck on how extract 'name,number' , informations refers courses in sorted , filtered table.

try this:

begin {     # set records separated empty lines     rs=""     # set fields separated newline, each record has 3 fields     fs="\n" } {     # remove undesired parts of every first line of record     sub("the course of ", "", $1)     sub(" :", "", $1)     sub("on ", "", $1)     # store rest in time , course     time=$1     course=$1     # remove time string extract course title     sub("^[^ ]* ", "", course)     # remove course title retrieve time string     sub(course, "", time)     # theory info second line per record     sub("course:theory:", "", $2)     # application info third line     sub("course:applicaton:", "", $3)     # if new course     if (! (course in header)) {         # save header information (first words of each line in output)         header[course] = course         theory[course] = "theory"         app[course] = "application"     }     # append relevant info output strings     header[course] = header[course] "," time     theory[course] = theory[course] "," $2     app[course] = app[course] "," $3  } end {     # each course found     (key in header) {         # print strings constructed         print header[key]         print theory[key]         print app[key]         print "" } 

i hope comments self explanatory, if have questions script sure ask them.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -