Sponsored Content
Top Forums Shell Programming and Scripting JSON structure to table form in awk, bash Post 303035621 by Gescad on Wednesday 29th of May 2019 12:34:25 PM
Old 05-29-2019
Quote:
Originally Posted by RudiC
Small modifications to your awk approach get you pretty close to what you want:

Code:
awk -F: '
BEGIN           {a01 = a02 = a03 = a04 = a05 = a06 = a07 = a08 = a09 = a10 = "NaN"
                 print "#text @data @fontName @fontSize @format @height          @type  @width      @x    @y"
                }
                {gsub (/[",]/,_)
                }
/#text/         {a01=$2}
/@data/         {a02=$2}
/@fontName/     {a03=$2}
/@fontSize/     {a04=$2}
/@fontStyle/    {a05=$2}
/@format/       {a06=$2}
/@height/       {a07=$2}
/@type/         {a08=$2}
/@width/        {a09=$2}
/@x/            {a10=$2}
/@y/            {print CNT++ " " a01 " " a02 " " a03 " " a04 " " a05 " " a06 " " a07 " " a08 " " a09 " " a10 " " $2
                 a01 = a02 = a03 = a04 = a05 = a06 = a07 = a08 = a09 = a10 = "NaN"
                }
'  file
#text @data @fontName @fontSize @format @height          @type  @width      @x    @y
0 NaN ABC NaN NaN NaN png 620.00 base64encoded 450.00 85.00 85.00
1 Text1 NaN Arial 12.0 NaN NaN 12.00 NaN 71.04 121.10 83.42
2 Text2 NaN Arial 12.0 NaN NaN 12.00 NaN 101.07 121.10 124.82
3 Text3 NaN Arial 12.0 NaN NaN 12.00 NaN 363.44 85.10 69.62
4 Text4 NaN Arial 12.0 NaN NaN 12.00 NaN 382.36 85.10 83.42
5 Text5 NaN Arial 12.0 NaN NaN 12.00 NaN 435.05 85.10 97.22

Thanks so much RudyC. It works pretty nice.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help on formatting output (Table Form)

Data in File ABC:DEFGHI:123 ABCZYE:DEFI:123 ABCFGD:DEF:123 ABCEERRRRR:DEFGHI:123 Expected Format 1 ABC DEFGHIFE 123 2 ABCZYE DEFI 123 3 ABCFGD DEF 123 4 ABCEERRRRR DEFGHI 123 However when i enter the following... (2 Replies)
Discussion started by: blurboy
2 Replies

2. Shell Programming and Scripting

How to create a C structure using table description.

There is table 'DEPT' in the database with the following desciption: Name Null? Type ------- -------- ------------------------ DEPTNO NOT NULL NUMBER(2) DNAME NULL VARCHAR2(14) LOC NULL VARCHAR2(13) Using shell script, I need to create a structure for the... (2 Replies)
Discussion started by: ehari
2 Replies

3. Shell Programming and Scripting

Converting form field to table format

May data Name = Andi Address = none Phone = 82728 Name = Peter Address = none Phone = 98799 The expected output Name,Address,Phone Andi,none,82728 Peter,none,98799 what i have done (6 Replies)
Discussion started by: before4
6 Replies

4. Shell Programming and Scripting

How to define a variable in a BASH script by using a JSON file online?

Hello, I would like to modify an existing script of mine that uses a manually defined "MCVERSION" variable and make it define that variable instead based on this JSON file stored online: https://s3.amazonaws.com/Minecraft.Download/versions/versions.json Within that JSON, I 'm looking for... (4 Replies)
Discussion started by: nbsparks
4 Replies

5. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

6. Shell Programming and Scripting

Getting data in table form

Hi, I have a csv file from which i am fetching few columns as below: IFILE=/home/home1/Report1.csv OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat if #Checks if file exists and readable then awk -F "," '(NR>4) {print $1,$6,$2,$3,$4,$5,$6}' ${IFILE} >> ${OFILE} fi cat $OFILE | mail... (7 Replies)
Discussion started by: Vivekit82
7 Replies

7. Shell Programming and Scripting

Parsing and Editing a json file with bash script

I am trying to automate editing of a json file using bash script. The file I initially receive is { "appMap": { "URL1": { "name": "a" }, "URL2": { "name": "b" }, "URL3": { "name": "c" }, } WHat I would like to do is replace... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

8. Shell Programming and Scripting

Extract hive table structure

Hi, I need to extract only the create table structure with columns alone. for eg hive_table show create table hive_table: create table hive_table(id number,age number) OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' LOCATION 'hdfs:/path/' I need only below ... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

9. Shell Programming and Scripting

Building JSON command with bash script

Hello. I'm new to bash script and I'm learning the basics by writing some scripts. Recently a friend of mine asked me if I could try to write a script to him to automate a couple of processes that uses JSON RPCs. I'll try to explain in few words the workflow just to contextualize the problem.... (48 Replies)
Discussion started by: psysc0rpi0n
48 Replies
JSON_PP(1)						User Contributed Perl Documentation						JSON_PP(1)

NAME
json_pp - JSON::PP command utility SYNOPSIS
json_pp [-v] [-f from_format] [-t to_format] [-json_opt options_to_json] DESCRIPTION
json_pp converts between some input and output formats (one of them is JSON). This program was copied from json_xs and modified. The default input format is json and the default output format is json with pretty option. OPTIONS
-f -f from_format Reads a data in the given format from STDIN. Format types: json as JSON eval as Perl code -t Writes a data in the given format to STDOUT. null no action. json as JSON dumper as Data::Dumper -json_opt options to JSON::PP Acceptable options are: ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref allow_singlequote allow_barekey allow_bignum loose escape_slash -v Verbose option, but currently no action in fact. -V Prints version and exits. EXAMPLES
$ perl -e'print q|{"foo":"XX","bar":1234567890000000000000000}|' | json_pp -f json -t dumper -json_opt pretty,utf8,allow_bignum $VAR1 = { 'bar' => bless( { 'value' => [ '0000000', '0000000', '5678900', '1234' ], 'sign' => '+' }, 'Math::BigInt' ), 'foo' => "x{3042}x{3044}" }; $ perl -e'print q|{"foo":"XX","bar":1234567890000000000000000}|' | json_pp -f json -t dumper -json_opt pretty $VAR1 = { 'bar' => '1234567890000000000000000', 'foo' => "x{e3}x{81}x{82}x{e3}x{81}x{84}" }; SEE ALSO
JSON::PP, json_xs AUTHOR
Makamaka Hannyaharamitu, <makamaka[at]cpan.org> COPYRIGHT AND LICENSE
Copyright 2010 by Makamaka Hannyaharamitu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-02-23 JSON_PP(1)
All times are GMT -4. The time now is 04:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy