Sponsored Content
Top Forums UNIX for Advanced & Expert Users Script to make a table from Named Variables. Post 302526983 by kumaran_5555 on Thursday 2nd of June 2011 04:16:19 AM
Old 06-02-2011
Hope this is what you are looking for
Code:
awk -F, '

{
for(i=1;i<NF;i++)
{
    pos=index($i,"="); 
    ARR[substr($i,0,pos-1),NR] =  substr($i,pos+1,length($i));
    SUB[substr($i,0,pos-1)]
}
max_row=NR;
}
END{
    for (a in SUB){ 
        printf " %s \t",a; }
    printf "\n";

    for(i=1;i<=max_row;i++){

        for (a in SUB){
            if(ARR[a,i] != "")            
                printf " %s \t",ARR[a,i];
            else
                printf " 0 \t";
        }    
        printf "\n"
    }

}' test.txt

Output
Code:
 a       b       c       d       e       f       g
 1       0       3       4       5       6       7
 11      12      0       14      15      16      17
 21      22      23      0       25      26      27
 31      32      33      34      0       36      37
 41      42      43      44      45      0       47
 51      52      53      54      55      56      0
 61      62      63      64      65      66      67
 71      72      73      74      75      76      77
 81      82      83      84      85      86      87
 91      92      93      94      95      96      97
 101     102     103     104     105     106     107
 111     0       113     114     115     116     117
 121     122     123     0       125     126     127
 131     132     133     134     135     136     137
 141     142     143     144     145     146     147
 151     152     153     154     155     0       157
 161     162     163     164     165     166     167
 171     172     173     174     0       176     177
 181     182     0       184     0       186     187
 0       0       0       0       0       0       0

You can change the formatting by chaning the printf statements.

Last edited by kumaran_5555; 06-02-2011 at 05:25 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Read variables from Access table

Hi! I've just started learning shell scripting, and have been somewhat 'thrown in at the deep-end and told to swim' so excuse my complete lack of knowledge and ignorance, but here goes... I've been given a unix script to 'tidy up'. Basically the script consists of the few lines of code being... (2 Replies)
Discussion started by: Sn33R
2 Replies

2. Shell Programming and Scripting

How to make variables in script function local?

Is it possible to make function variables local? I mean for example, I have a script variable 'name' and in function I have declared variable 'name' I need to have script's 'name' have the same value as it was before calling the function with the same declaration. The way to preserve a... (5 Replies)
Discussion started by: alex_5161
5 Replies

3. UNIX for Dummies Questions & Answers

MAKE and its macros and variables

I want to build a Makefile that simply takes a template file and modifies it (sed or perl, probably) before installing the result in the right place - my problem is creating the variable for substitution... So I have SYSTEM = SYS1 SYS2 SYS1_CHANNELS = CHANNEL1 CHANNEL2 CHANNEL4... (1 Reply)
Discussion started by: JerryHone
1 Replies

4. UNIX for Dummies Questions & Answers

Trying to make fixtures table with lynx --dump and pipe filters

Hey, I'm trying to make a nice clear table of fixtures. lynx --dump Fixtures & Reports | Fixtures | Arsenal.com | tail -n+360 | less #tail to remove 1st 360 line I'm trying to remove the 'Add to Calendar' bit next I tried pipping through sed but not sure if I did it right sed 's/\Add... (3 Replies)
Discussion started by: 64mb
3 Replies

5. Shell Programming and Scripting

Converting html table data into multiple variables.

Hi, Basically what I am trying to do is the following. I have created a shell script to grab timetabling information from a website using curl then I crop out only the data I need which is a table based on the current date. It leaves me with a file that has the table I want plus a small amount... (2 Replies)
Discussion started by: domsmith
2 Replies

6. Solaris

how do i make a route entry permanent in the routing table on solaris 8?

how do I make sure that the entry in the routing table on Solaris 8 stay permanent after rebooting the server. For example route add 172.20.1.60 -netmask 255.255.255.0 172.20.255.253 Each time the server reboots the entry disappears when using the command netstat -nr (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. UNIX for Advanced & Expert Users

How to make the variables of one script available for the other scripts?

Hello Everyone, I want to know how can we make the variables of one script available for the other script? for example i have three scripts variable_availability.sh,first.sh,second.sh and a file containing variables called common ---------------------------------- cat variable_availability.sh... (2 Replies)
Discussion started by: Kesavan
2 Replies

8. Shell Programming and Scripting

Find and replace variables using a csv table

I have a flat file (template) where I want to replace variables based upon a value in another file (csv). The variables in the template are named %VAR_X_z% The values are in the csv file and X is field 0 of each line and y field 1 and up. Example of the csv: Badidas, 13.00, 12.00, 11.00,... (8 Replies)
Discussion started by: biscayne
8 Replies

9. Shell Programming and Scripting

Make a table from a text file

Hi, I have a pipe separated text file. Can some someone tell me how to convert it to a table? Text File contents. |Activities|Status1|Status2|Status3| ||NA|$io_running2|$io_running3| |Replication Status|NA|$running2|$running3| ||NA|$master2|$master3|... (1 Reply)
Discussion started by: rocky88
1 Replies

10. UNIX for Dummies Questions & Answers

How to make entries background tasks in the table?

Hi am new to unix , when the background task is running how to put entry in the table and also if there is any issue how to stop the running task. can anyone help me... (1 Reply)
Discussion started by: Venkatesh1
1 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 07:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy