LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2012, 03:08 PM   #1
vrusu
LQ Newbie
 
Registered: Oct 2010
Posts: 8

Rep: Reputation: 0
translate cfg text file to json and json2text


hi
I have a config file like this one:

[sectionOne]
key1_1=value1_1
key1_n=value1_n
#this is a comment
[sectionTwo]
key2_1=value2_1
key2_n=value2_n

;this is a comment also
[SectionThree]
key3_1=value3_1
key3_n=value3_n

[SectionFor]
....

I need to translate this into json (and reverse), using minimal shell tools (no perl,python,php, just sed,awk available)
Code:
[
    {
        "sectionOne": {
            "key1_1": "value1_1",
            "key1_n": "value1_n"
        }
    },
    {
        "sectionTwo": {
            "key2_1": "value2_1",
            "key2_n": "value2_n"
        }
    },
    {
        "sectionThree": {
            "key3_1": "value3_1",
            "key3_n": "value3_n"
        }
    }
]
Is it possible?
Any idea would be greatly appreciated
thank you in advance!
 
Old 10-29-2012, 03:38 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,077

Rep: Reputation: Disabled
It seems that to determine the json lines to output from a line in the input you need to consider what are the contents of the previous (or none) and next (or none) line(s) of that input line.

This can be done with awk.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to the give path of the part.cfg file in %include command in ks.cfg. YOGESHAS87 Linux - Newbie 2 01-11-2011 04:33 AM
Is there a way to translate the text in a PDF from a language to another one? frenchn00b Linux - Software 2 01-10-2010 01:33 PM
BASH/No X: Using google translate to convert TXT files (translate) frenchn00b Programming 10 09-13-2009 10:55 PM
Is there a software than can translate whole big text ? Xeratul Linux - Software 5 02-16-2007 11:25 PM
how to add color text in ks.cfg (kickstart) kernel99 Linux - General 0 08-22-2005 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration