GNU-M4: split blank lines

How can I remove empty lines (redundant empy lines) from the input file using M4?

I know that I can add dnl to the end of each line of my script to suppress the output of a new line, but the empty lines that I mean are not in my script, but in the data file that is included (where I should not put dnl's ) .

I tried something like this:

 define(` ',`') 

(replace the new line with nothing) But that didn't work.

Thanks.

+4
source share
2 answers

I use divert() around my definitions:

  • divert(-1) will suppress the output
  • divert(0) will restore the output

For instance:

 divert(-1)dnl output supressed starting here define(..) define(..) divert(0)dnl normal output starting here use_my_definitions()... 
+3
source

I understand your problem as a data file with extra line breaks, which means that where you want to have the data<NL>moredata , you have things like data<NL><NL>moredata .

Here's a sample to cut / paste into your command line, which uses documents here to create a dataset and runs an m4 script to remove gaps in the dataset. You can see that patsubst replaces each instance of one or more lines of a new line in the sequence ( <NL><NL>* ) with exactly one new line.

 cat > data << ----- 1, 2 3, 4 5, 6 7, 8 9, 10 11, 12 e ----- m4 << "-----" define(`rmbreaks', `patsubst(`$*', ` *', ` ')')dnl rmbreaks(include(data))dnl ----- 
+1
source

All Articles