I run a minecraft server and like to periodically clean up my log files. I’ve developed a bunch of regex commands that I am able to use in gedit or notepad++, and they work perfectly, but I’d like to be able to automate the process.
The essential file-cleaning command would look like this:
cat server.log | sed -e 's/REGEXTODELETE//g' > server.log
but I’m having trouble getting the regex commands to translate properly to SED. I’m using sed on a CentOS6.3 box.
Here’s an example of a command that works in notepad++:
^[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ \[INFO\] Connection reset$
But when I enter it into my bash script:
cat server.clean.log | sed -e 's/^[0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]* \[INFO\] Connection reset$//g' > server.clean.log
it empties the whole file. I’ve looked all over, and I suspect I’m having an issue with whitespace, but after about an hour of searching I’m stuck. Any help is appreciated, and I can provide more examples.
The problem is you are overwriting the input file before it is being read.
Should be something like
In general,
will not work (reliably) since
infilewill get truncated beforeprogramgets a chance to read it