
Originally Posted by
vvpalin
Before i fall asleep can i ask a big favor ... Im probably going to write a firefox update script tomorrow and i was wondering how you could match a givin text string in a file and replace it with whatever you need. Im sure it will support wildcards so i really neednot ask but thats a must.
Thanks a bunch.
hint
: the command you're looking for is "sed"
Code:
cat inputfile | sed "s/string-to-replace/new-string/g" > outputfile
(Warning: Don't use the same file for input and output, as '>' will overwrite the file before "cat"ing it)
I recommend you to review the manpages of sed and google for "regular expressions" (you'll need it for wildcards etc). If sed does funny things you should also check your quotation inside the expressions (string-to-change & new-string). That should do the job...
@octet
I think it's the best way to become comfortable with the basic linux commands like grep and sed (and awk when you want do get really dirty) and of course fiddling with pipes. Second: experiment a bit with very linear scripts (simple sequence of commands to run) and use variables. Third: implement while/for-loops and if-clauses. The last would be to use functions inside the scripts (reduces the size of the script dramatically and it's better to understand and maintain). Your knowledge will grow linear to the complexicity of the problem you want to solve with the script ;-).
Overall it should not be too time consuming. IMHO a book is not necessary and your learning courve would be gained if you code your scripts from scratch instead of "jumping into the code" (i think that this makes most sense after you got around with the basics)
@KMDave - sorry I read your comment too late (but I think a little advise is ok).