1

次の形式のjsonファイルがあります。

[
    {
        "organization": "ABC", 
        "type": "School", 
        "contact": "Joe Schmo", 
        "contact_title": "Principal", 
        "mailing_address": "123 Main Street, Anytown, MA", 
        "phone": "214-555-5430",
        "fax": "214-555-5444"
    },
    {
        "organization": "XYZ",
        "type": "School",
        "contact": "John Doe", 
        "contact_title": "Asst Principal", 
        "mailing_address": "123 Main Street, Anycity, TX", 
        "phone": "512-555-5430",
        "fax": "512-555-5444"
    },
    .
    .
    .
    .
]

で始まる行を複製し、とで"organization"置き換えた後、ファイルに2回追加します。元のラインも残しておきたいです。私が欲しい出力は次のとおりです。"organization""company""long name"

[
    {
        "organization": "ABC",
        "company": "ABC",
        "long name": "ABC", 
        "type": "School", 
        "contact": "Joe Schmo", 
        "contact_title": "Principal", 
        "mailing_address": "123 Main Street, Anytown, MA", 
        "phone": "214-555-5430",
        "fax": "214-555-5444"
    },
    {
        "organization": "XYZ",
        "company": "XYZ",
        "name": "XYZ",
        "type": "School",
        "contact": "John Doe", 
        "contact_title": "Asst Principal", 
        "mailing_address": "123 Main Street, Anycity, TX", 
        "phone": "512-555-5430",
        "fax": "512-555-5444"
    },
    .
    .
    .
    .
]

awkまたはsedソリューションが望ましい。

4

1 に答える 1

4

これが1つの方法です:

sed '/organization/p;s/organization/company/p;s/company/long name/' file

ここに別のものがあります:

awk '$1~/organization/{print $0;sub(/organization/,"company");print $0;sub(/company/,"long name")}1' file
于 2013-03-21T20:00:31.827 に答える