search and replace by bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search and replace by bash
# 1  
Old 07-22-2005
search and replace by bash

Hello everyone!

I have a file: text.txt
Quote:
Unix is the best friend of Mac.
I will buy Mac.
and also a list of replacement: replace.txt (tabbed)
Code:
is	isn\'t
Mac	Windows
will	won\'t
\.\n	\!  			<--- ! plus 2 spaces

I want a script which will change text.txt as
Quote:
Unix isn't a best friend of Windows! I won't buy Windows.
I made a script:
Code:
#!/bin/bash
echo Please input the file of replacement list:
read list
for ($1=key) in $list ; do
	sed 's/$key/$2/g' > new.txt
done

But of course this won't work.
Well, there is no hidden meaning in this script, i think.
Please tell me the script.
# 2  
Old 07-23-2005
# 3  
Old 07-23-2005
Thanks vino.
I can use this.
And your code is simple!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - How to update header of scripts in one pass - multiline search/replace

Hello. A find command return a list of file. For each fileReplace the content starting with the first "§" (of two) ending with last "ɸ" (of two), regardless of the content ( five lines ) by the following content (exactly) : §2019_08_23§ # # ... (8 Replies)
Discussion started by: jcdole
8 Replies

2. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

3. UNIX for Dummies Questions & Answers

Help with search and replace or search only of / in vi

Hi all, I am editing a config file in vi that has a / on it. At the moment, search and replace looks alright as am able to use a # as a temporary separator, i.e. :,$s#/u01/app#/u02/app#g For doing a search, I have to escape the / do. So if I want to search for /u01/app, I am having to do... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

5. Shell Programming and Scripting

Can BASH handle mathematical operations and do a Search & Replace?

Hello, I have a bunch of xml file that needs to have edits made and I was wondering if a BASH script could handle it. I would like the script to look within my xml files and replace all integers greater than 5px with a value that is 25% smaller. For example, 100px = 75px. Since the integers... (12 Replies)
Discussion started by: jl487
12 Replies

6. Shell Programming and Scripting

Bash sed search and replace question

I have several files that I need to modify using sed. I know how to do that, but now a new requirement has come up. Now, I need to make changes to all lines that don't start with certain strings. For example, I need to change all lines except for lines that start with "a", "hello there",... (3 Replies)
Discussion started by: RickS
3 Replies

7. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

8. Shell Programming and Scripting

bash search and replace

Hello all, I would like to replace some text that are forwarded in standard output from a script, then save the replaced text to a file. The text i would like to replace is in the form of: 1 some text 1.1 other text 1.2 more text 1.2.1 still more text i would like to replace 1 some... (5 Replies)
Discussion started by: dolphin06
5 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

Help : Search and Replace

Hello, I'm lost on this one. I'm trying to search for a string in a file and replace it. But the string I'm searching for is on 2 seperate lines in the file and I only want to replace the 2nd occsrrance. This is what I know, but don't know how to select occurances that are on a seperate... (2 Replies)
Discussion started by: ctcuser
2 Replies
Login or Register to Ask a Question