Chris Bidmead spoke thus at 09:38:06 on Tue, 20 Nov 2001:
} > a pretty crude command line that crosses its fingers and hopes there
} > are no carats already in the text.
} >
} > tr '\n' ^ | sed -e 's/\^\^/$$/g ; s/\^/ /g' | tr '$' '\n'
}
} Or dollar signs, of course (just testing...).
} The caret limitation still applies, of course. Maybe a Master Sedder or
} Awkist might want to step forward at this point.
...or a perl-head (who will tell us that it can be done in one line of
perl), but I'm not a perl-head. Sooo, here's a mickey-mouse C prog I knocked
up in about 5 mins which pretty much does what you want (undoubtedly I've
done something really stupid and will regret posting this, but.... [And I
realise it could be more elegant, but I can't be bothered to improve it!])
charles
+-------------------------------------------------------------------------+
/*
* bidify.c
*
* Toy C prog to convert "newline-oriented" plain text to
* "paragraph-oriented" plain text for El Bid.
* Converts single newline chars to spaces but preserves two
* successive newline chars (delimiting a paragraph).
*
* Bugs: probably; certainly doesn't handle odd-numbered
* sequences of newline chars.
*
* Usage: bidify < textfile > newfile
*
* -- Charles Wiles 2001-11-20
*/
#include <stdlib.h>
#include <stdio.h>
int
main (void)
{
int c, nextc;
while ( (c=getchar()) != EOF )
{
if (c == '\n')
{
nextc=getchar();
if (nextc == EOF)
{
putchar(c);
exit(0);
}
else if (nextc == '\n')
{
putchar(c);
putchar(nextc);
}
else
{
putchar(' ');
putchar(nextc);
}
}
else
putchar(c);
}
exit(0);
}
|