Sponsored Content
Top Forums Shell Programming and Scripting Merge specific columns of two files Post 302915398 by RudiC on Tuesday 2nd of September 2014 06:06:31 PM
Old 09-02-2014
Not sure if I understood your requirement correctly, but give this a try (using adapted FILEn_VALUES as those provided do not show up in your sample):
Code:
FILE1_VALUE="E299"
FILE2_VALUE="E399"
awk     'NR==1          {DL=""
                         for (i=1; i<=NF; i++) {
                                 printf "%s%s", DL, $i
                                 DL="\t"
                                 if ($i == E1) break
                                }
                         getline < F2
                         for (j=1; j<=NF && $j != S2; j++) ;
                         for (k=j; k<=NF; k++) printf "%s%s", DL, $k
                         printf "\n"
                         next
                        }
                        {DL=""
                         for (k=1; k<=i; k++) { printf "%s%s", DL, $k; DL="\t" }
                         getline < F2
                         for (k=j; k<=NF; k++) printf "%s%s", DL, $k
                         printf "\n"
                        }
        ' FS="\t" E1="$FILE1_VALUE" S2="$FILE2_VALUE" F2="file2" file1
f0order CVorder Name    f0      RI_9    E99     E199    E299    E399    E499    E599    E699    E799    E899    E999    E1099   E1199   E1299
01      02      03      04      05      06      07      08      26      27      28      29      30      31      32      33      34      35

with file1
Code:
f0order CVorder Name    f0      RI_9    E99     E199    E299    E399    E499    E599    E699    E799    E899    E999
01      02      03      04      05      06      07      08      09      10      11      12      13      14      15

and file2
Code:
f0order CVorder Name    f0      RI_9    E399    E499    E599    E699    E799    E899    E999    E1099   E1199   E1299   E1399   E1499
21      22      23      24      25      26      27      28      29      30      31      32      33      34      35      36      37

This User Gave Thanks to RudiC For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

merge columns into one line after a specific pattern

Hi all, im a linux newbie, plz help! I have a file - box -------- Fox-2 -------- UF29 zip42 -------- zf-CW SNF2_N Heli_Z -------- Fox -------- Kel_1 box (3 Replies)
Discussion started by: sam_2921
3 Replies

2. Shell Programming and Scripting

Merge 2 columns/remove specific spaces

Hi, I have a requirement to remove certain spaces from a table of information, but I'm unsure where to start. A typical table will be like this: ABCDE 1 Elton John 25 12 15 9 3 ABCDE 2 Oasis 29 13 4 6 9 ABCDE 3 The Rolling Stones 55 19 3 8 6The goal is to remove only the spaces between... (11 Replies)
Discussion started by: danhodges99
11 Replies

3. Shell Programming and Scripting

merge the two files which has contain columns

Hi may i ask how to accomplish this task: I have 2 files which has multiple columns first file 1 a 2 b 3 c 4 d second file 14 a 9 .... 13 b 10.... 12 c 11... 11 d 12... I want to merge the second file to first file that will looks like this ... (2 Replies)
Discussion started by: jao_madn
2 Replies

4. Shell Programming and Scripting

Merge columns of different files

Hi, I have tab limited file 1 and tab limited file 2 The output should contain common first column vales and corresponding 2nd column values; AND also unique first column value with corresponding 2nd column value of the file that contains it and 0 for the second file. the output should... (10 Replies)
Discussion started by: polsum
10 Replies

5. UNIX for Dummies Questions & Answers

How to count specific columns and merge with unique ones?

Hi. I am not sure the title gives an optimal description of what I want to do. I have several text files that contain data in many columns. All the files are organized the same way, but the data in the columns might differ. I want to count the number of times data occur in specific columns,... (0 Replies)
Discussion started by: JamesT
0 Replies

6. UNIX for Dummies Questions & Answers

Merge columns from multiple files

Hi all, I've searched the web for a long time trying to figure out how to merge columns from multiple files. I know paste will append columns like so: paste file1 file2 file3 file4 file5 ... But this becomes inconvenient when you want to append a large number of files into a single file. ... (2 Replies)
Discussion started by: torchij
2 Replies

7. Shell Programming and Scripting

Merge columns on different files

Hello, I have two files that have this format: file 1 86.82 0.00 86.82 43.61 86.84 0.00 86.84 43.61 86.86 0.00 86.86 43.61 86.88 0.00 86.88 43.61 file 2 86.82 0.22 86.84 0.22 86.86 0.22 86.88 0.22 I would like to merge these two files such that the final file looks like... (5 Replies)
Discussion started by: kayak
5 Replies

8. Shell Programming and Scripting

Merge columns from multiple files

Hello and Good day I have a lot of files with same number of rows and columns.$2 and $3 are the same in all files . I need to merge $2,$3,$6 from first file and $6 from another files. File1: $1 $2 $3 $4 $5 $6... (8 Replies)
Discussion started by: ali.seifaddini
8 Replies

9. Shell Programming and Scripting

Merge files based on columns

011111123444 1234 1 20000 011111123444 1235 1 30000 011111123446 1234 3 40000 011111123447 1234 4 50000 011111123448 1234 3 50000 File2: 011111123444,Rsttponrfgtrgtrkrfrgtrgrer 011111123446,Rsttponrfgtrgtr 011111123447,Rsttponrfgtrguii 011111123448,Rsttponrfgtrgtjiiu I have 2 files... (4 Replies)
Discussion started by: vinus
4 Replies
GR_PLOT_INT(1)							   User Commands						    GR_PLOT_INT(1)

NAME
gr_plot_int.py - plot integer binary data using GNU Radio SYNOPSIS
gr_plot_int: [options] input_filenames DESCRIPTION
Takes a GNU Radio integer binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted ver- sus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the sam- ples. OPTIONS
-h, --help show this help message and exit -B BLOCK, --block=BLOCK Specify the block size [default=1000] -s START, --start=START Specify where to start in the file [default=0] -R SAMPLE_RATE, --sample-rate=SAMPLE_RATE Set the sampler rate of the data [default=1.0] SEE ALSO
gr_plot_char(1) gr_plot_const(1) gr_plot_fft_c(1) gr_plot_fft_f(1) gr_plot_float(1) gr_plot_int(1) gr_plot_iq(1) gr_plot_psd_c(1) gr_plot_psd_f(1) gr_plot_qt(1) gr_plot_short(1) gr_plot_int 3.5 December 2011 GR_PLOT_INT(1)
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy