Bashスクリプトを使用して変数を追加する

Bashスクリプトを使用して変数を追加する

次のテキストを含むファイルがあります。

//
//  test_file.h
//  test project
//
//  Created by Test User
//

#ifndef test_file_constants_h
#define test_file_constants_h

// Generic includes
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define PF_MASTER_VERSION 3.0.0
#define PF_BUILD_VERSION 1

#endif

PF_BUILD_VERSION実行するたびに1ずつ増加するスクリプトを作成する必要があります。見てみました。sedそしてAWKそして失敗しました!

ベストアンサー1

以下に基づくソリューションawk

awk '/^#define PF_BUILD_VERSION / {$3++} 1' infile >outfile  &&  mv outfile infile

おすすめ記事