Skip to content

Instantly share code, notes, and snippets.

@AyKo
Created May 19, 2012 18:49
Show Gist options
  • Save AyKo/2731932 to your computer and use it in GitHub Desktop.
Save AyKo/2731932 to your computer and use it in GitHub Desktop.
gawkでWindowsINIファイルから値を読み取るワンライナー
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