문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top