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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove string perl with first or last word is in a list
# 1  
Old 01-09-2015
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

Last edited by cyrine; 01-09-2015 at 07:04 PM..
# 2  
Old 01-09-2015
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.
# 3  
Old 01-10-2015
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 https://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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove everything after a word containing string?

Hello, I wish to remove any word coming after searched string found in a word. source*.txt #!bin/bash #test1 http://www.aa.bb.cc http://www.xx.yy http://www.11.22.44 #test2 http://www.11.rr.cd http://www.01.yy http://www.yy.22.tt #test3 http://www.22.qq.fc http://www.0x.yy... (15 Replies)
Discussion started by: baris35
15 Replies

2. Shell Programming and Scripting

Remove not only the duplicate string but also the keyword of the string in Perl

Hi Perl users, I have another problem with text processing in Perl. I have a file below: Linux Unix Linux Windows SUN MACOS SUN SUN HP-AUX I want the result below: Unix Windows SUN MACOS HP-AUX so the duplicate string will be removed and also the keyword of the string on... (2 Replies)
Discussion started by: askari
2 Replies

3. Shell Programming and Scripting

Remove last word of a string?

Hello I have a string that may or may not have 4 dots. The string is actualy a file within a folder, where multiple files are located. Files may look like: # ls * creds: 192.168.10.110 someserver shares: 192.168.10.110.Public someserver.sharefolder # I want to fill 2 variables,... (1 Reply)
Discussion started by: sea
1 Replies

4. Shell Programming and Scripting

Remove 1st word and _ from string

var=abc_cde_def_ghi_678.txt Expected output: cde_def_ghi_678.txt Is there a better way to achive this other than cut command? Basically, I need to remove the 1st word and _ from the string. Thanks. (1 Reply)
Discussion started by: vedanta
1 Replies

5. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

6. Shell Programming and Scripting

Remove a value from a string list...

I have something a bit tricky here and not sure how to go about fixing it. I am doing a ls on a directory to obtain a list of databases within a directory and assigning it to a string as you can see from below. The problem is there is a folder in there called apache. I do not want this to be... (3 Replies)
Discussion started by: LRoberts
3 Replies

7. Shell Programming and Scripting

How to remove duplicate sentence/string in perl?

Hi, I have two strings like this in an array: For example: @a=("Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive Oxygen Species","Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive... (9 Replies)
Discussion started by: vanitham
9 Replies

8. Shell Programming and Scripting

Change word in list - PERL

Hi, probably a newbie question..... But there it goes. :o I have a list words. This list is taken out of a file with grep and cut. my @system = (`grep up system_list| cut -d':' -f1` ); system= sm00xp03 sm01ftp02 sm00ssh12 What I want to have is a list, with each of the words in the... (1 Reply)
Discussion started by: pmpx
1 Replies

9. Shell Programming and Scripting

perl script to list filenames that do not contain given string

Hi, I need to write a perl script that should do a search recursively in all the '*.txt' files for the string "ALL -Tcb" and should print only the file names that do not contain this string. (21 Replies)
Discussion started by: royalibrahim
21 Replies

10. Shell Programming and Scripting

perl newbie: how to extract an unknown word from a string

hi, im quite new to perl regexp. i have a problem where i want to extract a word from a given string. but the word is unknown, only fact is that it appears as the second word in the string. Eg. input string(s) : char var1 = 'A'; int var2 = 10; char *ptr; and what i want to do is... (3 Replies)
Discussion started by: wolwy_pete
3 Replies
Login or Register to Ask a Question