using awk
if i have a bunch of pages loading bogus information and i need to change one number from 150 to 100....how do i find and replace in all the files the correct number. is awk my best bet? i've never used it. what is the best way to pipe grep into a awk command. preferable only "*.php" files?
thnx |
If you are wanting to replace text then sed is probably better. You probably don't need to use grep.
|
only reason i thought i might need to use grep is b/c i've got many php files in multiple directories that need numbers changed in them. so i'm trying to come up with a nice command to switch "word1" with "word2".....
|
you could probably use sed in conjunction with a "find -exec" command.
|
Here is a short online tutorial about using awk:
http://otn.oracle.com/pub/articles/dulaney_awk.html A couple of years ago I took a Unix class where we were briefly introduced to awk and sed. One of these days I need to go back and try to remember how to awk, sed, grep, fgrep, egrep, pipes and regular expressions. I only use Linux on my home computer and so far have not bothered to use those tools. |
Ooops, I got delayed several minutes in clicking "Submit Reply". Sorry that I did not notice the awk is no longer what you are planning to use.
|
which ever works....which ever lets me edit "word1" for "word2"...i'm like Rick485 i never bothered to learn awk or sed though i have used somewhat simple greps and finds. if someone knows i nice little pipped command to exchange/edit mulitple files in multiple directories...i would appreciate. as i contunie my search.....thnx guys...
*****UPDATE******* b/c at the moment i can't seem to get it to work. my experience with sed is only replacing "word1" with "word2" when outputing to the screen. it isn't actually finding and replacing the word(s) in the actual file. sed 's/ word1 / word2 /g' test isn't working. help would be appreciated. |
Code:
find /<your_base_directory_in_question> -iname "*.php" -exec sed -i "s/word1/word2/g" {} \; versions don't know about in-file replacement, and you'd have to build a script to mv original and copy around ... Cheers, Tink |
Hi Wedgeworth...
Just out of curiosity ... Did this work for you? Cheers, Tink |
thanks for the little bit of code. i ended up doing a few greps that redirected to a data file that i read from a did a simple
sed 's/word1/word2/g' $file1 > test99 cat test99 > $file1 commands. i think i already had this running before you shot me over your commands. i held onto it but haven't tried it out yet. plus i'm only running sed version 3.02 on this computer. but thanks for the help though. hopefully when i get my server updated on some newer versions it'll come in handy. thnx.... |
All times are GMT -5. The time now is 09:30 AM. |