Sponsored Content
Full Discussion: Replace exact word by perl
Top Forums UNIX for Beginners Questions & Answers Replace exact word by perl Post 302964938 by loktamann on Thursday 21st of January 2016 08:24:12 AM
Old 01-21-2016
Replace exact word by perl

my inputfile:

This is a test and only a test for production - prod.

Code:
echo "This is a test and only a test for production - prod" | perl -pi -e 's/prod/test/g'

outputfile:
Code:
This is a test and only a test for testuction - test

I only want to replace prod, not production.

I also tried to use sed:

Code:
echo "This is a test and only a test for production - prod" | sed -e 's/prod/test/g'
This is a test and only a test for testuction - test

Thank you in advance for helping.

Moderator's Comments:
Mod Comment Pleas use code tags for you code and data, nothing else... Thanks

Last edited by vbe; 01-21-2016 at 09:38 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace aword in a.The replaced word should not be overwitten in perl(details inside)

Hi i am trying to write a perl program where i have to open a 1)directory "unit" 2) rename the files in the dir say file1.txt;file2.txt...file5.txt to file1_a.txt;file2_a.txt,....file5_a.txt ;file1_x.txt ;file2_x.txt 3) open these renamed files and replace the words lets say file1_a.txt... (7 Replies)
Discussion started by: madhul2002
7 Replies

2. Shell Programming and Scripting

Exact Word Match

I'm trying to find a exact word match but couldn't do it. ABC ABC_NE Searching for ABC_NE tried grep -w </ABC_NE/> grep "^ABC_NE$" but didn't worked , any awk variants would also help. ---------- Post updated at 08:40 AM ---------- Previous update was at 06:48 AM ---------- I... (2 Replies)
Discussion started by: dinjo_jo
2 Replies

3. Shell Programming and Scripting

Replace exact word with blank

i have a file with the below content file1.txt ALERTADMIN.FIELD ALERTADMIN.TX_ALERTS_LOG i have another file file2 ALERTADMIN.FIELD ALERTADMIN.FIELD_WS ALERTADMIN.SECTION_FIELD_WS ALERTADMIN.TX_ACCT_PROCESSING_WORK_TABLE ALERTADMIN.TX_ACCT_REVIEW_EXEC_METRICS... (2 Replies)
Discussion started by: lavnayas
2 Replies

4. Shell Programming and Scripting

perl: replace multiple word on a line

Hi All, If I have a line as following: ( MA "vertical" ) How can I convert it to as below: ( BC "horizontal" ) Thanks, --Michael (6 Replies)
Discussion started by: mxn731
6 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

Grep Exact word

This may be stupid question but not able to solve it. How to grep exact word and line along with it. TEST:/u00/app/oracle/product/10.2.0/TEST:N TEST2:/u00/app/oracle/product/10.2.0/ODS:N TEST3:/u00/app/oracle/product/10.2.0/TEST:N TEST4:/u00/app/oracle/product/10.2.0/ODS:N... (4 Replies)
Discussion started by: tapia
4 Replies

8. UNIX for Advanced & Expert Users

Perl command to replace word in file...

Hi, I want to search for a specific word in file and replace whole line with new text. e.g. 1) I have file with below lines APP=ABCD 12/12/2012 DB=DDB 01/01/2013 I need perl command which will check for APP=$VAL and replace whole line with APP=$NEWVAL $NEWDT Simlarly need a... (2 Replies)
Discussion started by: mgpatil31
2 Replies

9. Shell Programming and Scripting

How to get the exact word in awk?

Hi, i have a file that contains the following: ARTPRD01_app = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.222.3.4)(PORT = 1540)) (CONNECT_DATA = (SERVICE_NAME = artprd01.com) ARTPRD01 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.223.3.1)(PORT =... (2 Replies)
Discussion started by: reignangel2003
2 Replies

10. Shell Programming and Scripting

How to take exact word from output.?

Hi i am writing and i want to take very first word "A924A5FC"from the below o/p A924A5FC 0910055313 P S SYSPROC SOFTWARE PROGRAM ABNORMALLY TERMINATED A924A5FC 0908091913 P S SYSPROC SOFTWARE PROGRAM ABNORMALLY TERMINATED A924A5FC 0906090313 P S SYSPROC SOFTWARE... (4 Replies)
Discussion started by: scriptor
4 Replies
Dist::Zilla::App::Command::test(3pm)			User Contributed Perl Documentation		      Dist::Zilla::App::Command::test(3pm)

NAME
Dist::Zilla::App::Command::test - test your dist VERSION
version 4.300020 SYNOPSIS
dzil test [ --release ] [ --no-author ] [ --automated ] [ --all ] DESCRIPTION
This command is a thin wrapper around the test method in Dist::Zilla. It builds your dist and runs the tests with the AUTHOR_TESTING environment variable turned on, so it's like doing this: export AUTHOR_TESTING=1 dzil build --no-tgz cd $BUILD_DIRECTORY perl Makefile.PL make make test A build that fails tests will be left behind for analysis, and dzil will exit a non-zero value. If the tests are successful, the build directory will be removed and dzil will exit with status 0. OPTIONS
--release This will run the test suite with RELEASE_TESTING=1 --automated This will run the test suite with AUTOMATED_TESTING=1 --no-author This will run the test suite without setting AUTHOR_TESTING --all Equivalent to --release --automated --author AUTHOR
Ricardo SIGNES <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo SIGNES. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-21 Dist::Zilla::App::Command::test(3pm)
All times are GMT -4. The time now is 05:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy