Jill Ceke Posted December 2, 2013 Share Posted December 2, 2013 Hi, I'm very new to these forums. I was wondering if someone could help an AWK beginner with a pattern matching an actor to his appearance in movies, which would be stored as records. Let's say we have a database of 4 movies (each movie a record with name, studio + year, and actor fields with a blank line separating the four records) and need to pattern match and actor's name and return his name followed by the movies he has appeared in (in chronological order). In this case I would like to pattern match Jennifer Lawrence and create an output file that lists Jennifer Lawrence at the top followed by the names of movies she has appeared in by chronological order, each on separate lines (just an output file of 3 lines). Any help would be appreciated. Thank you! :D CasablancaWB 1942Humphrey Bogart: Rick BlaineIngrid Bergman: Ilsa LundPaul Henreid: Victor LaszloHunger GamesLionsgate 2012Jennifer Lawrence: Katniss EverdeenJosh Hutcherson: Peeta MellarkLiam Hemsworth: Gale HawthorneLike CrazyParamount 2011Anton Yelchin: Jacob HelmFelicity Jones: Anna GardnerJennifer Lawrence: SamanthaRaging BullUnited Artists 1980Robert de Niro: Jake LaMottaJoe Pesci: Joey LaMottaCathy Moriarty: Vickie Thailer Link to comment Share on other sites More sharing options...
snaphat (Myles Landwehr) Member Posted December 3, 2013 Member Share Posted December 3, 2013 Hi, I'm very new to these forums. I was wondering if someone could help an AWK beginner with a pattern matching an actor to his appearance in movies, which would be stored as records. Let's say we have a database of 4 movies (each movie a record with name, studio + year, and actor fields with a blank line separating the four records) and need to pattern match and actor's name and return his name followed by the movies he has appeared in (in chronological order). In this case I would like to pattern match Jennifer Lawrence and create an output file that lists Jennifer Lawrence at the top followed by the names of movies she has appeared in by chronological order, each on separate lines (just an output file of 3 lines). Any help would be appreciated. Thank you! :D Casablanca WB 1942 Humphrey Bogart: Rick Blaine Ingrid Bergman: Ilsa Lund Paul Henreid: Victor Laszlo Hunger Games Lionsgate 2012 Jennifer Lawrence: Katniss Everdeen Josh Hutcherson: Peeta Mellark Liam Hemsworth: Gale Hawthorne Like Crazy Paramount 2011 Anton Yelchin: Jacob Helm Felicity Jones: Anna Gardner Jennifer Lawrence: Samantha Raging Bull United Artists 1980 Robert de Niro: Jake LaMotta Joe Pesci: Joey LaMotta Cathy Moriarty: Vickie Thailer var="Jennifer Lawrence"; echo $var; awk -F".:." -v var="$var" '/'"$var"'/{print $2}' FILENAME EDIT: Throw that in a shell script and redirect to a file. Link to comment Share on other sites More sharing options...
Recommended Posts