C++
Remove multiple newlines from a file
===========================
Warning 20150507: Just noticed, that the sed-expression also filters identical “not empty” lines from you file! This is not what I wanted. So if you have code with array-initialisations which use the same lines or multiple consecutive calls of the same function, then be careful and check the result of the following command with diff!
Hint 20150508: take a look at this code-snippet. Just copy&paste&compile&run.
===========================
Task to achieve is: remove the superfluous double or triple empty lines between functions. One empty line as separator is acceptable. Two are annoying ..
Workflow is: filter the original source-file and put it into a new file. Remove the old one and replace it.
1 |
$ cat source.cpp | sed '$!N; /^\(.*\)\n\1$/!P; D' > source_tmp.cpp && rm source.cpp && mv source_tmp.cpp source.cpp |
Maybe I should put it into a shellscript which parses the given directory recursively and applies this to all *., *cpp, *.hpp ..
useless data pt. II
If you ever wondered how many times you compiled your project {today, the last week, ..} and got no answer: here is a clue.
Add the command “date >> someTextFile.txt” as custom command to QtCreator as build step before make is executed.
This will insert everytime you compile a new line with the current time into a textfile. Processing that data is your own task.
Small hint: if you are lazy and just want some alltime-stats use “wc compileDates.txt” 😉
Edit 20150407:
If you are just interested in the date, use this:
1 2 3 4 5 6 7 8 |
marcelpetrick$ cat compileDates.txt | cut -c 1-10 | uniq -c 14 Thu Mar 26 31 Fri Mar 27 16 Mon Mar 30 20 Tue Mar 31 48 Wed Apr 1 41 Thu Apr 2 16 Tue Apr 7 |
Qt-inheritance: hitting rock bottom
- missing semicolon
- missing Q_Object
- missing “public” for the inherited class
- ctor/dtor private ..