Question

Discount's configure.sh script generates some dynamic comments at the start of the config.h file:

/*
 * configuration for markdown, generated Fri 28 Jan 2011 16:13:46 EST
 * by tim@Orion.local
 */
#ifndef __AC_MARKDOWN_D
#define __AC_MARKDOWN_D 1

[...]

Which makes for some useless patches when embedding discount inside a git project, so I remove them before committing. I want to automate the output from configure.sh so I can upgrade discount inside the project quicker, but I'm not that well versed with awk/sed. I've got this line in my script:

tail -n +5 config.h > ../discount-config/config.h

But I'd like to replace this with something more future-proof, so it won't mangle the file if later versions of discount have more/less than 4 lines of comments.

Was it helpful?

Solution

How about using sed?

For example, if you can assume that the top comment will always start at the first line of the file:

$ cat test.h
/*
 * configuration for markdown, generated Fri 28 Jan 2011 16:13:46 EST
 * by tim@Orion.local
 */
#ifndef __AC_MARKDOWN_D
#define __AC_MARKDOWN_D 1

/*
 * Test
 */

int x;
$ sed '1,/^ *\*\/ *$/ { d; }' test.h
#ifndef __AC_MARKDOWN_D
#define __AC_MARKDOWN_D 1

/*
 * Test
 */

int x;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top