awk - list to tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - list to tables
# 8  
Old 04-24-2008
Hi mens, it really helpful, I did it and Works OK!:
cat code.ksh

#! /usr/bin/ksh
awk '{
for(f=1; f<=NF; f++)
r2c[f","NR] = $f
} END {
for(f=1; f<=NF; f++) {
for(row=1; row<=NR; row++)
printf("%s\t", r2c[f","row])
print ""
}
}' $1

./code <file.txt> ... and voila!
Thanks shamrock
# 9  
Old 04-24-2008
Lobaria: can you check whether NF and NR are defined in the END part? Just add a print statement. My hunch is that they will be zero in your version of awk.

Do you have nawk, or mawk, or gawk, or XPG4 awk on your system? Then try with one of those instead.

Modding the script so that it remembers the last values of NR and NF before the END section is not a complicated fix, as such.
# 10  
Old 04-24-2008
Dear era, dear shamrock,

Thanks - Problem solved !
I was thinking along the same lines and installed gawk and it worked just fine.

Does anybody have an idea what the problem could be with my version of awk?


######################
### gawk script (r2c.sh)
### Converts rows into columns
######################

#! /bin/sh

gawk '{
for(f=1; f<=NF; f++)
r2c[f","NR] = $f
} END {
for(f=1; f<=NF; f++) {
for(row=1; row<=NR; row++)
printf("%s\t", r2c[f","row])
print ""
}
}' $1

##########################
# 11  
Old 04-24-2008
Well, my speculation would be that it doesn't remember the NF and NR values in END, since strictly speaking they are no longer defined in that context (intuitively speaking, at least).
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare with 2 tables

I have 3 file inputs, file1 20160302|5485368299953|96|510101223440252|USA|5485368299953|6|800|2300|0 20160530|5481379883742|7|510101242850814|USA|5481379883742|5|540|2181|1500 20160513|5481279653404|24|510100412142433|INDIA|5481279653404|3|380|1900|0... (1 Reply)
Discussion started by: radius
1 Replies

2. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

3. Shell Programming and Scripting

Selecting tables

Hi, Can anyone help me that, How to see the table fields in Oracle database through shell script(ksh). I have tried with the following: sqlplus -s $user/$passwd@$sid << SQL >> session.log select * from Testtab.sql I'm not able to see anything.. Thanks (4 Replies)
Discussion started by: zxcjggu708
4 Replies

4. Shell Programming and Scripting

Display tables of 6

I'm new to linux and unix I would like to know how to display tables of 6 line after line Output should be 1*6 = 6 2*6 = 12 3*6 = 18 4*6 = 24 etc I can display line by line but not continuously Any suggestion (3 Replies)
Discussion started by: electricair
3 Replies

5. Shell Programming and Scripting

awk to create two HTML Tables

I am working on awk script to generate an HTML format output. With input file as below I am able to generate a HTML file however I want to saperate spare devices in a different table than rest of the devices and which has only Bunch ID, RAW Size and "Bunch Spare" status columns. INPUT File : ... (2 Replies)
Discussion started by: dynamax
2 Replies

6. UNIX for Dummies Questions & Answers

VI editor and tables

I have a host table that looks similar like this: # IP Name Comment 10.10.10.1 Lab1-1 # Static for Lab1 subnet 10.10.10.2 Lab1-2 # Static for Lab1 subnet 10.10.10.3 Lab1-3 ... (2 Replies)
Discussion started by: mjl927
2 Replies

7. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

8. Shell Programming and Scripting

PHP: list into tables

how would i go about having a index.php page in a folder, in the folder several files named greece.rar and france.rar and other countrys. could php get a list of these, put the names into a table, listed downwards, and the file-names clickable to open that file.? (2 Replies)
Discussion started by: perleo
2 Replies
Login or Register to Ask a Question