Remove string perl with first or last word is in a list

Hello,

I try to delete all strings if their first or last word is one of this list of words : "the", "i", "in", "there", "this", "with", "on", "we", "that", "of"
For example if i have this string in an input file "with me" this string will be removed,
Example: input
"the european union"
"would like to"
"would like"
"of the european"
"the european parliament"
"the member states"
output
"would like to"
"would like"

Any idea please
Tahnk you

Simple way is to:

  1. have an array with the list of words
  2. read line from input file. capture the first and last word using regex
  3. search for the captured words in the array from step 1
  4. if found, skip processing the line in focus and goto step 2
  5. if not found, print line to stdout / write to file as necessary
  6. repeat steps 2, 3, 4, 5 until eof

Please let us know what you have tried.

Hi, cyrine.

Welcome to the forum.

Your title includes the word perl. If you are required to use language perl, please state why. If this is homework or for a class, then see the sub-forum http://www.unix.com/homework-and-coursework-questions/ , follow the rules, and ask your question there.

If not required to use perl, there are many other possible solutions.

Does your data file actually have quote characters around the lines?

It's usually a good idea to say what OS you are using, as well as responding to balajesuri's question about Please let us know what you have tried. .

Best wishes ... cheers, drl