We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Append word

faithless1
faithless1 asked
on
Medium Priority
397 Views
Last Modified: 2012-05-11
Hello,

I'm looking for a way to append a word at the end of each record which does not contain specific words (i.e. store or rocket)

example

store rocket went
phone laptop

output (append a word - in this case I specify store)
store rocket went
phone laptop store

Thank you

Comment
Watch Question

Kim RyanIT Consultant

Commented:
Try this
if ( $line !~ /\bstore\b/ or $line !~ /\brocket\b/)  # key word not found, \b means search on word boundary
{
    $line .= ' store'; # append store to string
}
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
a1j

Commented:
sorry replace <IN> with <> in above's answer

Author

Commented:
a1j - Thank you! ! worked perfectly

One other question is what tweak would i need to make to append the word before matches.

Thanks again

a1j

Commented:
Just replace
$_=$_.'word'
with
$_='word'.$_
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.