The usual way of doing this sort of thing is to use lexer start conditions (sometimes called start states), and have either the lexer or parser set the current start condition at the appropriate time. You can find info on this in the documentation for flex, but basically, your lexer would be something like:
%s SPECIAL
%%
<INITIAL>[\n] ; /* normally ignore newlines */
<SPECIAL>[\n] return *yytext; /* but not in the SPECIAL state */
/* other flex rules */
%%
void enableNewlines() { BEGIN(SPECIAL); }
void disableNewlines() { BEGIN(INITIAL); }
then in your bison code, you might have actions like
input: bang command '\n' {
/* handle the command */
disableNewlines(); }
bang: '!' { enableNewlines(); }
the basic idea is that when you recognized enough of something to know that there's a required newline coming up, you go into that special start state, and then once you've parsed the newline, you go back into the 'normal' start state. You need to be careful of the exact sequencing as in some cases, bison will read ahead a token (getting the lookahead) before reducing an action.
An alternative approach that may be simpler or more complex is to have the lexer always return newlines and have your grammar explicitly ignore them everywhere they might occur. This may be verbose (lots of places in the grammar).