Construct 3 column table from one column list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Construct 3 column table from one column list
# 1  
Old 07-26-2011
Question Construct 3 column table from one column list

Hi all!

trying my best to parse a public site for information (ie fiscal year and turnover) about corporations.

Doing this by having a file with business name and registration number (search key)
the file bolag.txt currently looks like this

Burgundy 556732-7217
AcademicSearch 556406-9879


and looping through it and using cURL to fetch the file and then doing some rather unpretty sanitization of the output.

Code:
#!/bin/sh

awk '{print $1, $2}' bolag.txt | while read BNAME BNUMBER
do

URL="http://allabolag.se?what=$BNUMBER"
echo $BNAME
curl -s $URL |  grep bokTable | sed -e 's/<[^>]*>//g' | awk 'NR==1,NR==9' | awk 'NR!=4 && NR!=5 && NR!=6'  
echo "--"
done

My problem is that the output is like this for each found entry

Code:
Business Name
            2010-12
            2009-12
            2008-12
            10 532
            2 084
            0
--

I'm not getting my head around how to make the first 3 rows into column headers and populating the second row with lines 4-6 in a new file.

I obviously need to make the cleanup better as well, but currently at least that works.

Any help is greatly appriciated!

Cheers

Martin

Last edited by martindebruin; 07-26-2011 at 09:39 AM.. Reason: forgot to include data file
# 2  
Old 07-26-2011
I'm not clear wit your requirement.

In the example you posted,

Code:
2010-12            2009-12            2008-12

need to treated as columns, what about next three rows of data? ( 5 values exists in the example you provided, how you wil fit them under 3 columns).
# 3  
Old 07-26-2011
Hi

Sorry. Each result will give a header row with dates. Which will be quite redundant. But I reckon I'll be able to deal with that mess once all the data is aligned in columns.

I'm sure there's a better way, but I can't see it Smilie
# 4  
Old 07-26-2011
Not sure still.

Instead you please post the sample input data and the output you are expecting.
# 5  
Old 07-26-2011
output

ok

so currently with my two row sample input file i get

Code:
Burgundy
            2010-12
            2009-12
            2008-12
            10 532
            2 084
            0
--
AcademicSearch
            2010-12
            2009-12
            2008-12
            46 706
            37 984
            53 632
--

What I'd like to get would be an output like

Code:
   year1       year2        year3
firm1 turnover1 turnover2 turnover3
firm2 turnover1 turnover2 turnover3

# 6  
Old 07-26-2011
Pls post the sample "output" that you get for the input you provided.

Sorry , but I don't knw what the "turnovers" here are from.
# 7  
Old 07-26-2011
my previous post includes the output i currently get.

What I want to achive is to get


Code:
                  2010-12       2009-12        2008-12
Burgundy 10 532 2 084 0 
AcademicSearch 46 706 37 984 53 63

So. Each result/company from the script will yield 6 rows where the first 3 will be years and the last 3 will be each year's turnover.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

3. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

4. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

5. Shell Programming and Scripting

From column to table

Hi, I have an ascii file containing information. This file is n x m lines. Is there a way to generate an ascii file where the information is stored as n x m table instead? The m columns should be tab separated. Thanks a lot, Sarah (11 Replies)
Discussion started by: f_o_555
11 Replies

6. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

7. UNIX for Advanced & Expert Users

Data from table to column

Hi All, in bash I have a text file which is something like 7.96634E-07 1.0000 0.00000E+00 0.0000 0.00000E+00 0.0000 1.59327E-06 0.7071 2.23058E-05 0.1890 6.61207E-05 0.1098 1.13919E-04 0.0865 1.47377E-04 0.0747 .... .... 0.00000E+00 0.0000 0.00000E+00 0.0000 ... (6 Replies)
Discussion started by: f_o_555
6 Replies

8. UNIX for Dummies Questions & Answers

average of a column in a table

Hello, Is there a quick way to compute the average of a column data in a numerical tab delimeted file? Thanks, Gussi (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. Shell Programming and Scripting

file in to the column of the table

Hi I am ETL person. I have a table in Oracle having one of its column defined as BLOB where it can hold huge data. When i generate a file in DataStage and place it in a path. and i would like dump the file in to the column of the table having datatype as BLOB. (0 Replies)
Discussion started by: sant_leo
0 Replies
Login or Register to Ask a Question