Created
May 19, 2012 18:49
-
-
Save AyKo/2731932 to your computer and use it in GitHub Desktop.
gawkでWindowsINIファイルから値を読み取るワンライナー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gawk '/^[ \t]*\[.*\]/{m=0} /^[ \t]*\[SECTION\]/{m=1} m==1&&/^[ \t]*FIELD/{sub(/^[^=]+=[ \t]*/,""); print $0}' | |
| # SECTIONを対象のセクション名に置き換える | |
| # FIELDを対象のフィールド名に置き換える | |
| # | |
| # 例: | |
| # <<target.ini>> | |
| # [Section1] | |
| # field1 = 5656 | |
| # field2 = ABCD | |
| # [Section2] | |
| # field1 = 4646 | |
| # | |
| # cat target.ini | gawk '/^[ \t]*\[.*\]/{m=0} /^[ \t]*\[Section1\]/{m=1} m==1&&/^[ \t]*field1/{sub(/^[^=]+=[ \t]*/,""); print $0}' | |
| # 5656 | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment