[Nottingham] AWK script

stripes stripes at roppa.demon.co.uk
Thu Mar 24 00:58:52 UTC 2011


Dear Group,

I have the following AWK script which I am running on the file
wpaper.rdf of which there is the first record below. The real file is
4000 lines lines long and every record is separated by 2 blank lines.
If I run the script with name=Harry or any variation of Harry.R.Clarke
it returns the Author-Name: field and all the papers he has written as
in the first example below. If the name variable is anything else
name=Don.Harding in the second example it only returns the titles of
the papers he has written.  The variable is not being set until after
the first loop can somebody tell me why, where my error is and how I
can change it to make it behave? It only works properly if the
Author-Name searched for is in the first record in the file.

It is usable at present as I know the author names but I would like it
to work correctly.

awk '{RS=""};{FS="\n"};{for(i=1;i<NF;i++){if($i ~ name ){print
$i}break}}{for(i=1;i<NF;i++){if($i ~ name){{for(i=1;i<NF;i++){if($i ~
/Title:/){print $i }}}}}}'

Template-Type: ReDIF-Paper 1.0
Author-Name: Harry R Clarke
Author-Name-First: Harry
Author-Name-Last: Clarke
Author-Workplace-Name: School of Economics and Finance, La Trobe University
Author-Name: William J Reed
Author-Name-First: William
Author-Name-Last: Reed
Author-Workplace-Name: School of Economics and Finance, La Trobe University
Title: The Tree-Cutting Problem in a Stochastic Environment: The case
of Age Dependent Growth
Creation-Date: 1989
Number: 1989.01
Handle: RePEc:ltr:wpaper:1989.01


awk '{RS=""};{FS="\n"};{for(i=1;i<NF;i++){if($i ~ name ){print
$i}break}}{for(i=1;i<NF;i++){if($i ~ name){{for(i=1;i<NF;i++){if($i ~
/Title:/){print $i }}}}}}' name=Harry wpaper.rdf

Author-Name: Harry R Clarke
Title: The Tree-Cutting Problem in a Stochastic Environment: The case
of Age Dependent Growth
Title: Land Development and Wilderness Conservation Policies Under
Uncertainty: A Synthesis


awk '{RS=""};{FS="\n"};{for(i=1;i<NF;i++){if($i ~ name ){print
$i}break}}{for(i=1;i<NF;i++){if($i ~ name){{for(i=1;i<NF;i++){if($i ~
/Title:/){print $i }}}}}}' name=Don.Harding wpaper.rdf

Title: Applying shape and phase restrictions in generalized dynamic
categorical models of the business cycle

Regards
Stripes.



More information about the Nottingham mailing list