Sponsored Content
Top Forums Shell Programming and Scripting What is find and replace command in unix? Post 302462764 by rajkumar_g on Friday 15th of October 2010 02:28:53 AM
Old 10-15-2010
thanks for suggestion

I know find command to search a string but i dont know how to replace with other string. for example.
i am finding for Hosts.
find . -type f -exec grep -l "Hosts" {} \;
but idont know how to replace with "Server".


Thanks & Regards
Rajkumar g
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find and replace command in one line using one command

Hi, I have a entry in the file as ::BSNL GUJARAT::India::OUT::NAT::REWEL::POSTPAID::919426199995 if u see this, i have the delimiter as :: , all i want is to replace "::" as ":" so how to do that.. pls help thanks (10 Replies)
Discussion started by: vasikaran
10 Replies

2. Shell Programming and Scripting

find and replace command

Hi, i used to do on soalris box but in linux box i am not able to do advice is appreciated uname -a Linux intranet 2.4.20-pre3 #1 Tue May 6 17:55:35 IST 2008 i686 unknown $ find /usr/local/ -type f | xargs perl -pi -e 's/172.16.1.14/172.16.1.27/g' Can't remove /usr/local/bin/dbhome:... (1 Reply)
Discussion started by: prakash.gr
1 Replies

3. Shell Programming and Scripting

Character Find and replace in Unix or Perl

Hi, I am stuck with an problem and want some help, what i want to do is There is a directory name temp which include file named t1.txt, t2,txt, t3.txt and so on. These files contains data, but there are some bad character also that is % present in the files , I want to write the script... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

4. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

5. Shell Programming and Scripting

sed find and replace command not working

Hi, Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command. sed 's/^\(.\{289\}\)-/\1O/' filename sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed. Thanks in Advance Sara Video tutorial on how to use code tags in The... (9 Replies)
Discussion started by: Sara183
9 Replies

6. Shell Programming and Scripting

Find and Replace Path in UNIX

Hi All, How can i find and replace the one path to another path with in the file. For Example: Search_path=/search/path replace_path=/replace/path I used the following command but not usefull, please help me regarding the same. sed 's_/search/path_/replace/path_' file_name >... (6 Replies)
Discussion started by: nsyed.dw
6 Replies

7. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

8. UNIX for Dummies Questions & Answers

Find and Replace string in UNIX

Hi All, Greetings. I have a .dat file which somewhere in its content contains symbol ""^ I want to replace it with "^ I tried with SED command but could not achieve what i wanted sed -e "s/'""^'/'"^'/ig" filename.dat (5 Replies)
Discussion started by: MaddyS
5 Replies

9. Shell Programming and Scripting

Find and Replace in UNIX Scripting

Hi, Need your advices, Input : select code,status,input from VIEW1.VIEWNAME where IDU_CD IN ('S','N') and status_col='derived')) union select code,status,input from VIEW1.VIEWNAME2 where date='#p1' Expected output : select code,status,input from VIEW1.VIEWNAME where... (2 Replies)
Discussion started by: Nandy
2 Replies

10. UNIX for Beginners Questions & Answers

Find command + replace the extension (.xxx) by *

Hello, I'm on HP Unix and in a Job, I tried to extract all files from a folder, and replace the extension (.xxxx) by '*' , remove duplicates and move the result in a file.. Example : Folder has : ABC, CCC.txt, CCC.sf, CCC.sfd, DDD I need to generate and output file with : ... (6 Replies)
Discussion started by: royinfo.alain
6 Replies
STR_REPLACE(3)								 1							    STR_REPLACE(3)

str_replace - Replace all occurrences of the search string with the replacement string

SYNOPSIS
mixed str_replace (mixed $search, mixed $replace, mixed $subject, [int &$count]) DESCRIPTION
This function returns a string or an array with all occurrences of $search in $subject replaced with the given $replace value. If you don't need fancy replacing rules (like regular expressions), you should always use this function instead of preg_replace(3). PARAMETERS
If $search and $replace are arrays, then str_replace(3) takes a value from each array and uses them to search and replace on $subject. If $replace has fewer values than $search, then an empty string is used for the rest of replacement values. If $search is an array and $replace is a string, then this replacement string is used for every value of $search. The converse would not make sense, though. If $search or $replace are arrays, their elements are processed first to last. o $search - The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. o $replace - The replacement value that replaces found $search values. An array may be used to designate multiple replacements. o $subject - The string or array being searched and replaced on, otherwise known as the haystack. If $subject is an array, then the search and replace is performed with every entry of $subject, and the return value is an array as well. o $count - If passed, this will be set to the number of replacements performed. RETURN VALUES
This function returns a string or an array with the replaced values. EXAMPLES
Example #1 Basic str_replace(3) examples <?php // Provides: <body text='black'> $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); // Provides: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); // Provides: 2 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; ?> Example #2 Examples of potential str_replace(3) gotchas <?php // Order of replacement $str = "Line 1 Line 2 Line 3 Line 4 "; $order = array(" ", " ", " "); $replace = '<br />'; // Processes 's first so they aren't converted twice. $newstr = str_replace($order, $replace, $str); // Outputs F because A is replaced with B, then B is replaced with C, and so on... // Finally E is replaced with F, because of left to right replacements. $search = array('A', 'B', 'C', 'D', 'E'); $replace = array('B', 'C', 'D', 'E', 'F'); $subject = 'A'; echo str_replace($search, $replace, $subject); // Outputs: apearpearle pear // For the same reason mentioned above $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text); echo $output; ?> NOTES
Note This function is binary-safe. Caution Replacement order gotcha Because str_replace(3) replaces left to right, it might replace a previously inserted value when doing multiple replacements. See also the examples in this document. Note This function is case-sensitive. Use str_ireplace(3) for case-insensitive replace. SEE ALSO
str_ireplace(3), substr_replace(3), preg_replace(3), strtr(3). PHP Documentation Group STR_REPLACE(3)
All times are GMT -4. The time now is 09:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy