paste two tables of different sizes and fill blanks with NaN


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers paste two tables of different sizes and fill blanks with NaN
# 1  
Old 04-04-2012
Question paste two tables of different sizes and fill blanks with NaN

Hello,

I am pasting two tables of 6x4 and 4x4 together to get a 10x8 output. I want to fill the blank values with a NaN (Not a Number). How can I do this?

Thanks,
Guss
# 2  
Old 04-04-2012
IS this what you mean?

4x4
Code:
4 4 4 4
4 4 4 4
4 4 4 4

6x4
Code:
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6
6 6 6 6

gives:
Code:
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6
4 4 4 4 4 4 4 4 
4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4

This is how I interpret you question. It doesn't make a lot of sense to me. Please give us sample input & desired output.
# 3  
Old 04-04-2012
Hi Jim,

My file1 (6 rows x 4 columns) is:
Code:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4

My file2 (4 rows x 4 columns) is:
Code:
5 6 7 8
5 6 7 8
5 6 7 8
5 6 7 8

paste file1 -d '\t' file2 > file 3 as shown below

Code:
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4    
1 2 3 4


However I wan the bottom two rows that do not have values for cols 5-8 to be filled with NaN (shown below using 'N' for abbreviation.)

Code:
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 N N N N
1 2 3 4 N N N N


Thanks for your input!
~Guss

Last edited by Corona688; 04-04-2012 at 04:13 PM..
# 4  
Old 04-04-2012
Code:
paste t1 t2 | awk -v OFS="\t" '{ (NF>M) && M=NF; for(N=1; N<=M; N++) length($N) || $N="NaN" } 1'

1       2       3       4       5       6       7       8
1       2       3       4       5       6       7       8
1       2       3       4       5       6       7       8
1       2       3       4       5       6       7       8
1       2       3       4       NaN     NaN     NaN     NaN
1       2       3       4       NaN     NaN     NaN     NaN

$

This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk replace cells with NaN/delete if condition

Hello, I will like to delete/replace $3 with NaN. condition $3>-2000 (file1.dat) to produce out.dat. I want to retain the structure of the table. I use this code, this output only $3. Any idea on how to modify this code. Thank you. awk -v OFS='' '{for(i=1; i<=NF; i++) if ($i > -2000 || $i ==" >... (4 Replies)
Discussion started by: geomarine
4 Replies

2. Programming

Strange value of the double type variable: -nan(0x8000000000000)

I am confused by the value of "currdisk->currangle" after adding operation. Initially the value of "currdisk->currangle" is 0.77500000000000013, but after adding operation, it's changed to "-nan(0x8000000000000)", Can anyone explain ? Thanks! The following is the occasion of gdb debugging. 3338 ... (8 Replies)
Discussion started by: 915086731
8 Replies

3. UNIX for Dummies Questions & Answers

Cacti SNMP Generic OID template, NaN problem

Hello All, I have installed cacti and I have Nan values on created graph. I really appreciate any help. I have done the following: 1. Linux Ubuntu 12.04.2 LTS 64 bits 2. apt-get install cacti // the cacti Version 0.8.7i was installed 3. Accessed "http://MyIP/cacti/index.php" 4. Set SNMP... (0 Replies)
Discussion started by: AndreiM
0 Replies

4. Shell Programming and Scripting

Leading blanks

Hi Ich have a list as follows 73 5 100 45 81 4 and I would like to have an output (on screen) like that 73 5 100 45 81 4 (6 Replies)
Discussion started by: lazybaer
6 Replies

5. UNIX for Dummies Questions & Answers

cut and paste from two tables

Hello, I want to be able to cut and paste columns from two tables in one command. Presently I do the following: cut -f 1,3-6,9 table1.in > table1.out cut -f 7,6,1-3 table2.in > table2.out paste table1.out -d '\t' table2.out > MergedTable.out Is there a better way to do this? ... (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

6. Programming

Blanks vs: Nulls

I'm relatively new to Pro*C programming. In the following example: char name; EXEC SQL SELECT 'John Doe' INTO :name FROM DUAL; "John Doe" is in positions 0-7, blanks in 8-19, and a null in 20. I would really prefer the null to be in position 8 and I don't care what's after that. I wrote a... (1 Reply)
Discussion started by: ebock
1 Replies

7. Shell Programming and Scripting

How to use grep to check NAN value and nonexistense element in file

Hi, I have a file which computes fields number and some column produced "nan" I would like to convert the "nan" value to 0 basically. q=`echo $i $j |awk '{printf("%f",($2/($1+$2)))}' The above is the command which I use for computation. However, I would like to check if $1 and $2 is 0, it... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

8. 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

9. UNIX for Advanced & Expert Users

numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this : sed '/./=' file | sed '/./N; s/\n/ /' gives me 1 aaaa 2 bbbbbb 4 cccccc 5 ffkkkfff 6 ffsdfdfs I would like something like this: 1 aaaaa 2 3 bbbbbb 4 5 cccccc And so... (6 Replies)
Discussion started by: wisher115
6 Replies

10. Shell Programming and Scripting

blanks in file name

I have a file with a list of filenames. I want to work loopwise through the file and operate on each of the listed files. Normally I'd do something like: for file in `cat $mydir/file-list` do echo $file >> $mydir/my.log cp $mydir/$file $newdir done the problem is that my... (1 Reply)
Discussion started by: LisaS
1 Replies
Login or Register to Ask a Question