Turning data collected vertically to a table
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I have data was collected and saved in file "data.txt", in the following format:
<$ MG_nr>
</200>company-type:Engine1
</210>company-name:STR
</220>address:XX
</230>nr:4568789
</240>zipcode:08765
</250>place:ljkmljubi
</260>phone:786754678
</270>fax:76756778
</$>
<$ MG_nr>
</280>company-type:Engine2
</290>company-name:STR
</300>address:XX
</310>nr:7675678
</320>zipcode:87867
</330>place:jkhgkl
</340>phone:87865
</350>fax:876578
</$>
<$ MG_nr>
</360>company-type:Engine3
</370>company-name:STR
</380>address:XX
</390>nr:78675467
</400>zipcode:87657
</410>place:uiytryui
</420>phone:87656788976
</430>fax:8976535467
</$>
<$ MG_nr>
</440>company-type:Engine4
</450>company-name:STR
</460>address:XX
</470>nr:876578y67
</480>zipcode:786578
</490>place:kljhgryui
</500>phone:8976546789
</510>fax:989765
</$>
I wanted to turn this to a spreadsheet like this:
Type Name Address Nr Zipcode Place Phone Fax
------------------------------------------------------------------------
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
I tried this code which I found it on U & L site
, and I tried to replicate it:
#!/bin/bash
cut -d'>' -f 2 data.txt | awk -F: '
/^company-type:/type[c]=$2
/^company-name:/name[c]=$2
/^address:/address[c]=$2
/^nr:/nr[c]=$2
/^zipcode:/zipcode[c]=$2
/^place:/place[c]=$2
/^phone:/phone[c]=$2
/^Fax:/fax[c]=$2;c++
END
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
for(x in type)
printf "%-10s %3d %s %s %s %s %s %sn",
substr(type[x],2),
company-name[x],
address[x],
nr[x],
zipcode[x],
place[x]
phone[x]
fax[x]
' data.txt
But this didn't work, it only prints the header!!!
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
I can't figure out what I am doing wrong?
I appreciate any advice! or any suggestion to make the code above works and simpler.
awk cut text-formatting
New contributor
add a comment |Â
up vote
5
down vote
favorite
I have data was collected and saved in file "data.txt", in the following format:
<$ MG_nr>
</200>company-type:Engine1
</210>company-name:STR
</220>address:XX
</230>nr:4568789
</240>zipcode:08765
</250>place:ljkmljubi
</260>phone:786754678
</270>fax:76756778
</$>
<$ MG_nr>
</280>company-type:Engine2
</290>company-name:STR
</300>address:XX
</310>nr:7675678
</320>zipcode:87867
</330>place:jkhgkl
</340>phone:87865
</350>fax:876578
</$>
<$ MG_nr>
</360>company-type:Engine3
</370>company-name:STR
</380>address:XX
</390>nr:78675467
</400>zipcode:87657
</410>place:uiytryui
</420>phone:87656788976
</430>fax:8976535467
</$>
<$ MG_nr>
</440>company-type:Engine4
</450>company-name:STR
</460>address:XX
</470>nr:876578y67
</480>zipcode:786578
</490>place:kljhgryui
</500>phone:8976546789
</510>fax:989765
</$>
I wanted to turn this to a spreadsheet like this:
Type Name Address Nr Zipcode Place Phone Fax
------------------------------------------------------------------------
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
I tried this code which I found it on U & L site
, and I tried to replicate it:
#!/bin/bash
cut -d'>' -f 2 data.txt | awk -F: '
/^company-type:/type[c]=$2
/^company-name:/name[c]=$2
/^address:/address[c]=$2
/^nr:/nr[c]=$2
/^zipcode:/zipcode[c]=$2
/^place:/place[c]=$2
/^phone:/phone[c]=$2
/^Fax:/fax[c]=$2;c++
END
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
for(x in type)
printf "%-10s %3d %s %s %s %s %s %sn",
substr(type[x],2),
company-name[x],
address[x],
nr[x],
zipcode[x],
place[x]
phone[x]
fax[x]
' data.txt
But this didn't work, it only prints the header!!!
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
I can't figure out what I am doing wrong?
I appreciate any advice! or any suggestion to make the code above works and simpler.
awk cut text-formatting
New contributor
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have data was collected and saved in file "data.txt", in the following format:
<$ MG_nr>
</200>company-type:Engine1
</210>company-name:STR
</220>address:XX
</230>nr:4568789
</240>zipcode:08765
</250>place:ljkmljubi
</260>phone:786754678
</270>fax:76756778
</$>
<$ MG_nr>
</280>company-type:Engine2
</290>company-name:STR
</300>address:XX
</310>nr:7675678
</320>zipcode:87867
</330>place:jkhgkl
</340>phone:87865
</350>fax:876578
</$>
<$ MG_nr>
</360>company-type:Engine3
</370>company-name:STR
</380>address:XX
</390>nr:78675467
</400>zipcode:87657
</410>place:uiytryui
</420>phone:87656788976
</430>fax:8976535467
</$>
<$ MG_nr>
</440>company-type:Engine4
</450>company-name:STR
</460>address:XX
</470>nr:876578y67
</480>zipcode:786578
</490>place:kljhgryui
</500>phone:8976546789
</510>fax:989765
</$>
I wanted to turn this to a spreadsheet like this:
Type Name Address Nr Zipcode Place Phone Fax
------------------------------------------------------------------------
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
I tried this code which I found it on U & L site
, and I tried to replicate it:
#!/bin/bash
cut -d'>' -f 2 data.txt | awk -F: '
/^company-type:/type[c]=$2
/^company-name:/name[c]=$2
/^address:/address[c]=$2
/^nr:/nr[c]=$2
/^zipcode:/zipcode[c]=$2
/^place:/place[c]=$2
/^phone:/phone[c]=$2
/^Fax:/fax[c]=$2;c++
END
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
for(x in type)
printf "%-10s %3d %s %s %s %s %s %sn",
substr(type[x],2),
company-name[x],
address[x],
nr[x],
zipcode[x],
place[x]
phone[x]
fax[x]
' data.txt
But this didn't work, it only prints the header!!!
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
I can't figure out what I am doing wrong?
I appreciate any advice! or any suggestion to make the code above works and simpler.
awk cut text-formatting
New contributor
I have data was collected and saved in file "data.txt", in the following format:
<$ MG_nr>
</200>company-type:Engine1
</210>company-name:STR
</220>address:XX
</230>nr:4568789
</240>zipcode:08765
</250>place:ljkmljubi
</260>phone:786754678
</270>fax:76756778
</$>
<$ MG_nr>
</280>company-type:Engine2
</290>company-name:STR
</300>address:XX
</310>nr:7675678
</320>zipcode:87867
</330>place:jkhgkl
</340>phone:87865
</350>fax:876578
</$>
<$ MG_nr>
</360>company-type:Engine3
</370>company-name:STR
</380>address:XX
</390>nr:78675467
</400>zipcode:87657
</410>place:uiytryui
</420>phone:87656788976
</430>fax:8976535467
</$>
<$ MG_nr>
</440>company-type:Engine4
</450>company-name:STR
</460>address:XX
</470>nr:876578y67
</480>zipcode:786578
</490>place:kljhgryui
</500>phone:8976546789
</510>fax:989765
</$>
I wanted to turn this to a spreadsheet like this:
Type Name Address Nr Zipcode Place Phone Fax
------------------------------------------------------------------------
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
I tried this code which I found it on U & L site
, and I tried to replicate it:
#!/bin/bash
cut -d'>' -f 2 data.txt | awk -F: '
/^company-type:/type[c]=$2
/^company-name:/name[c]=$2
/^address:/address[c]=$2
/^nr:/nr[c]=$2
/^zipcode:/zipcode[c]=$2
/^place:/place[c]=$2
/^phone:/phone[c]=$2
/^Fax:/fax[c]=$2;c++
END
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
for(x in type)
printf "%-10s %3d %s %s %s %s %s %sn",
substr(type[x],2),
company-name[x],
address[x],
nr[x],
zipcode[x],
place[x]
phone[x]
fax[x]
' data.txt
But this didn't work, it only prints the header!!!
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
I can't figure out what I am doing wrong?
I appreciate any advice! or any suggestion to make the code above works and simpler.
awk cut text-formatting
awk cut text-formatting
New contributor
New contributor
edited 2 hours ago
New contributor
asked 4 hours ago
Nadal
455
455
New contributor
New contributor
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
This is a simpler solution:
awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t
company-type company-name address nr zipcode place phone fax
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
The field separator -F
enables awk
to read the data in columns based on :
and >
, then awk
prints the third column which is equivalent to the required actual data, at the same time it construct the header.
This output is piped to xargs
which reorganizes it in eight columns. Finally, the command column
adds tab and equal spaces between the resultant columns.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
This is a simpler solution:
awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t
company-type company-name address nr zipcode place phone fax
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
The field separator -F
enables awk
to read the data in columns based on :
and >
, then awk
prints the third column which is equivalent to the required actual data, at the same time it construct the header.
This output is piped to xargs
which reorganizes it in eight columns. Finally, the command column
adds tab and equal spaces between the resultant columns.
add a comment |Â
up vote
4
down vote
accepted
This is a simpler solution:
awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t
company-type company-name address nr zipcode place phone fax
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
The field separator -F
enables awk
to read the data in columns based on :
and >
, then awk
prints the third column which is equivalent to the required actual data, at the same time it construct the header.
This output is piped to xargs
which reorganizes it in eight columns. Finally, the command column
adds tab and equal spaces between the resultant columns.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
This is a simpler solution:
awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t
company-type company-name address nr zipcode place phone fax
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
The field separator -F
enables awk
to read the data in columns based on :
and >
, then awk
prints the third column which is equivalent to the required actual data, at the same time it construct the header.
This output is piped to xargs
which reorganizes it in eight columns. Finally, the command column
adds tab and equal spaces between the resultant columns.
This is a simpler solution:
awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t
company-type company-name address nr zipcode place phone fax
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765
The field separator -F
enables awk
to read the data in columns based on :
and >
, then awk
prints the third column which is equivalent to the required actual data, at the same time it construct the header.
This output is piped to xargs
which reorganizes it in eight columns. Finally, the command column
adds tab and equal spaces between the resultant columns.
edited 1 hour ago
answered 2 hours ago
Goro
8,70354384
8,70354384
add a comment |Â
add a comment |Â
Nadal is a new contributor. Be nice, and check out our Code of Conduct.
Nadal is a new contributor. Be nice, and check out our Code of Conduct.
Nadal is a new contributor. Be nice, and check out our Code of Conduct.
Nadal is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475055%2fturning-data-collected-vertically-to-a-table%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password