Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Find and Change String in File
Name: DontKnowCrapBoutUnix Date: February 22, 2003 at 21:45:10 Pacific OS: Mac OS 10.1.5 CPU/Ram: 400mhz 384 ram
Comment:
The short story is I want to find a string in a file and change it. Here are the details. I'm looking for a way to change every occurence of $source to "JavTemp" in a file called JavTemp2.java. $source is a variable. This is what I've got: sed s/$source/JavTemp/g JavTemp2.java > JavTemp.java
The problem, of course, is that sed recognizes $source as a pattern rather than a variable. Is there a way to make sed behave the way I want or is there a better tact?
Nope. I'm wondering if this a Mac problem. Does this work on other systems?
0
Response Number 5
Name: Jimbo Date: February 23, 2003 at 14:40:39 Pacific
Reply:
After reading the post again, i realized that $source is a variable, not a string. If you want to perform variable substitution with sed, then enclose the expresion in double quotes.
source="some string" sed "s/$source/JavTemp/g" JavTemp2.java > JavTemp.java
Summary: hello, may i know how can i find and change string in multiple file...i had refer some of the post here .. but found that all is about find and change string in a file only..let say i want to change a...
Summary: Hi, Can anyone help me with the command to do the following search and replace in the following files: Files: file1 file2 file3 Search String: "GET /thisfile?id= Replace String: "GET /thisfile?source=...
Summary: I need to find an certain string in a flat file at a specific field position number. For example, the string '01' in positions 25,26 in a specific file. Is there a nice clean way to do that? Thanks!...