Sign in to follow this  
Followers 0

2 posts in this topic

Posted

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
 

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.