Compare columns and rows with template, and fill empty slots.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare columns and rows with template, and fill empty slots.
# 1  
Old 03-28-2010
Compare columns and rows with template, and fill empty slots.

Hi,
I'm working on a script that will take the contents of a file, that is in a row and column format, and compare it to a arrangment file. Such that if there is any or all blanks in my content file, the blank will be filled with a flag and will retain the row and column configuration.

Ex.

Content file is as follows,
Code:
100.000   200.000
123.423      4.354
  45.452    34.345
123.765

Arrangment file is as follows,
Code:
***.***   ***.***
***.***    ***.***
***.***   ***.***
***.***   ***.***
***.***   ***.***

So we have an arrangement of 5 rows and 2 columns. And where the Content file doesn't match the Arrangement file I would like it to be displayed as.

Code:
100.000   200.000
123.423      4.354
  45.452    34.345
123.765   EMTPY
EMPTY     EMPTY

SO far I've been able to do

Code:
nl Arrangement_file > numbered_arrangement_file

But I can't get the Contents_file to have a beginning column of the list of lines up to 5. It will only go up to the 4th, and stop because that how much content is in the file.

Thanks for any help in advance.

Last edited by radoulov; 03-28-2010 at 06:37 AM.. Reason: Please use code tags!
# 2  
Old 03-28-2010
Code:
awk 'NR==FNR{arr[FNR]=$1"\t"$2;next}END{
 for(i=0;++i<=FNR;){
   split(arr[i],sp,"\t")
   print (sp[1]==""?"Empty":sp[1]),(sp[2]==""?"Empty":sp[2])
   }
    }' content_file arrangement_file

# 3  
Old 03-28-2010
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris:

Code:
awk 'NR == FNR { r[NR] = $0; next }
{ 
  split(r[FNR], t)
  for (i = 0; ++i <= NF;)
    $i = t[i] ? t[i] : "EMPTY"
  }1' content_file arrangement_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fill in missing rows with zero to have uniform table

Hello, I have two files of same structure except some rows are missing randomly in each file. How do I fill the missing rows to have the exact ID column (S01 ~ S96) and rest columns filled with "0" with awk? The purpose of this step is to join the two files side by side. The closest thread is... (17 Replies)
Discussion started by: yifangt
17 Replies

2. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

3. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

4. UNIX for Dummies Questions & Answers

Filling in the empty columns with rows above them

Hi, I have a text file where some of the values in columns are missing: Input: QhFudW3dKSYL2NTQUA 1 11133999-11134048 uhIp9KxB6USIy16CEY 1 11126760-11126774 11126775-11126805 11128065-11128068 6epeZ6CTNW4Au8uXys 1 24480823-24480872 Tp3nvutucBZ13CjuXc 1 155204870-155204891... (3 Replies)
Discussion started by: evelibertine
3 Replies

5. Emergency UNIX and Linux Support

Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command dd if=/dev/zero of=file_2GB bs=2048000 count=2000 We are planning to automate the task where taking input for % of size as one input and the name of the file system... (8 Replies)
Discussion started by: chandu123
8 Replies

6. UNIX for Dummies Questions & Answers

Filling in the empty columns with the rows above them

I have a text file that looks like the following: 5.644 39.2% 0.00 0.50 rs1695626 4 -0.003 0.21% 0.03 0.73 rs1763326 3 -0.001 0.03% 0.00 0.89 5.645 39.2% 0.00 0.50 rs770721 2 -0.002 0.07% 0.01 0.84... (7 Replies)
Discussion started by: evelibertine
7 Replies

7. UNIX for Dummies Questions & Answers

Filling in the empty columns using the rows above them

I have a text file that looks like the following: rs529715 CFD rs1550758 CIDEB Magmas rs12542019 CPNE1 RBM12 rs10515181 CPNE1 RBM12 rs4411112 CPT1A Some rows have 1 column, whereas some have 2. The ones that have 2 columns have one column (1st column) that start with rs. I need to... (6 Replies)
Discussion started by: evelibertine
6 Replies

8. UNIX for Dummies Questions & Answers

Deleting all rows with empty columns

I have a text file that looks like this: 1 rs523634 8.22486 1 1 rs585160 8.22488 1 rs497228 8.2249 1 1 rs600933 8.225 1 rs480106 8.22531 1 rs600199 8.22533 1 rs529015 8.22534 1 rs598894 8.22534 I want to delete the rows with empty... (2 Replies)
Discussion started by: evelibertine
2 Replies

9. UNIX for Dummies Questions & Answers

Fill in columns

Hi, I've got a file with several columns where some entries are missing. Example: a b c d f g h j k l p y r I need to replace the empty spaces with zero, so the new file would be: a b c d f 0 g h j k 0 l p y 0 r The original file is tab delimited. Many thansk for... (3 Replies)
Discussion started by: zajtat
3 Replies

10. Shell Programming and Scripting

fill in missing columns

It can't be that hard, but I just can't figure it out: I have file like: File Sub-brick M_1 S_1 M_2 S_2 M_4 S_4 ... xxx 1 214 731 228 621 132 578 ... and would like to get 0 0 where M_3 S_3 is missing xxx 1 214 731 228 621 0 0 132 578 ... I wrote following script, but can't figure out... (3 Replies)
Discussion started by: avvk
3 Replies
Login or Register to Ask a Question