I have a huge SQL file that gets executed on the server. The dump is from my machine and in it there are a few settings relating to my machine. So basically, I want every occurance of "c://temp"
to be replace by "//home//some//blah"
How can this be done from the command line?
Try sed? Something like:
Escaping all those slashes makes this look horrible though, here's a simpler example which changes foo to bar.
As others have noted, you can choose your own delimiter, which would prevent the leaning toothpick syndrome in this case:
The clever thing about sed is that it operating on a stream rather than a file all at once, so you can process huge files using only a modest amount of memory.
gawk
sed is a good choice for large files.
It is a good choice because doesn't read the whole file at once to change it. Quoting the manual:
The relevant manual section is here. A small explanation follows
Example
Just for completeness. In place replacement using
perl
.No backslash escapes required either. ;)
The -p will treat this script as a loop, it will read the specified file line by line running the regex search and replace.
-i This flag should be used in conjunction with the -p flag. This commands Perl to edit the file in place.
-e Just means execute this perl code.
Good luck
There's also a non-standard UNIX utility, rpl, which does the exact same thing that the
sed
examples do; however, I'm not sure whetherrpl
operates streamwise, sosed
may be the better option here.