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.
Search and replace string in files
Name: AndrewG1976 Date: June 21, 2007 at 19:29:08 Pacific OS: Solaris 9 CPU/Ram: 440Mhz/512MB
Comment:
Hi,
Can anyone help me with the command to do the following search and replace in the following files:
Name: ghostdog Date: June 21, 2007 at 20:09:14 Pacific
Reply:
the first thing to do when you don't know something is to look it up, books, online search, you name it. Then try to do it, and if still don't get it, you can post to forums to ask. I've thought of not posting, but because today is a friday (coming to the weekends) and i am happy, i can give you a head start. :-) [code] sed 's/<search string>/<replacement>/g' "file" [/code]
0
Response Number 2
Name: AndrewG1976 Date: June 21, 2007 at 20:57:28 Pacific
Reply:
I should have mentioned that I did research this and I came across the sed command but it doesn't work for me. I think because of the ? and = characters in my string.
I tried the following and neither worked:
sed 's/"GET /thisfile?id=/"GET /thisfile?source=1&id=/g' file1
I also tried escaping the " and ? and =
sed 's/\"GET \/thisfile\?id\=/\"GET \/thisfile\?source\=1\&id\=/g' file1
0
Response Number 3
Name: ghostdog Date: June 21, 2007 at 23:04:21 Pacific
Reply:
ok..this is trivial..provide a sample input file content.
0
Response Number 4
Name: AndrewG1976 Date: June 21, 2007 at 23:38:58 Pacific
Reply:
The file is an Apache log file. Sample input file content:
Summary: I am working w/ this huge matrix file. Now in this matrix file 2nd column is strings. lets say its contain red, blue, black. now i can not load this file in matlab. so i wanted to change red to 1 bl...
Summary: 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. $so...
Summary: Hi, I intend to do a search and replace for specific words for files under a directory (inclusive of subdirectories). I know how to do that file by file using sed and redirect it to the original file....