Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Dynamically merging 2 files on header values Post 302826979 by RudiC on Thursday 27th of June 2013 04:38:18 PM
Old 06-27-2013
Please use code tags as required by forum rules!
Try this
Code:
awk     'NR==1          {CNT=split($0, HD)}
         NR==FNR        {print; next}
         FNR==1         {SCN=split ($0, SB); for (j=1; j<=CNT; j++)
                                                  for (i=1; i<=SCN; i++)
                                                        if (SB[i] == HD[j]) COL[j]=i
                         next}
                        {for (j=1; j<=CNT; j++) {T=COL[j]; printf "%s%s", T?$T:"", (j==CNT)?"\n":OFS}}
        ' FS="," OFS="," file1 file2
Column1,column2,column3,column4,column5,column6
Abc,123,zyz,456,asd,098
,656,wzw,,,898

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

dynamically adding values in c-shell

I am needing to create a variable(changing) and assign it a value(changing) ... I am using C-Shell.. Example: foreach account in ($Accountlist) set account_connect = "$account/$account_pass" end I want to make set account_connect to store various values ? $account_connect did not... (3 Replies)
Discussion started by: shafi2all
3 Replies

2. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

3. UNIX for Advanced & Expert Users

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

4. Programming

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

5. Shell Programming and Scripting

Modifying the values of dynamically named arrays

Hi all, In ksh, I'm trying to loop through all of my arrays, named array1, array2, array3..., and update the indices. But I'm getting errors and I'm not sure how to fix them. The errors are ./parse.sh: 6+1: not found The code is: eval \${array$c}=$(eval \${array$c}+1 ) Any help... (12 Replies)
Discussion started by: nicksantos1
12 Replies

6. UNIX for Dummies Questions & Answers

Merging two text files by a column and filling in the missing values

Hi, I have to text files that I want to merge by the first column. The values in the first column pretty much match for the first part. However there are some values that are present in column 1 and not present in column 2 or vice versa. For such values I would like to substitute X for the... (9 Replies)
Discussion started by: evelibertine
9 Replies

7. Shell Programming and Scripting

Generate a DML dynamically based off of header record

I have the following scenario where I need to use a header record from a file and generate a DML based off of it... E.g.: The header can change periodically with an additional column in between or remove a col.... Sample header : (head -1 sample.txt)... (17 Replies)
Discussion started by: anduzzi
17 Replies

8. UNIX for Beginners Questions & Answers

Concatenate column values when header is Matching from multiple files

there can be n number of columns but the number of columns and header name will remain same in all 3 files. Files are tab Delimited. a.txt Name 9/1 9/2 X 1 7 y 2 8 z 3 9 a 4 10 b 5 11 c 6 12 b.xt Name 9/1 9/2 X 13 19 y 14 20 z 15 21 a 16 22 b 17 23 c 18 24 c.txt Name 9/1 9/2... (14 Replies)
Discussion started by: Nina2910
14 Replies

9. Shell Programming and Scripting

Merging two files to form header

Dear experts required you support to achieve below i need the file 2 values show on top of file 1 for mentioned valuesENTER CREDENTIALS or beside this please support to achieve the expected result . if I get the result 2 that will be better I have two files File 1 ENTER CREDENTIALS BILLING... (4 Replies)
Discussion started by: mirwasim
4 Replies

10. UNIX for Beginners Questions & Answers

How to print multiple required columns dynamically in a file using the header name?

Hi All, i am trying to print required multiple columns dynamically from a fie. But i am able to print only one column at a time. i am new to shell script, please help me on this issue. i am using below script awk -v COLT=$1 ' NR==1 { for (i=1; i<=NF; i++) { ... (2 Replies)
Discussion started by: balu1234
2 Replies
flow-split(1)						      General Commands Manual						     flow-split(1)

NAME
flow-split -- Split flow files into smaller files. SYNOPSIS
flow-split [-gGhn] [-b big|little] [-C comment] [-d debug_level] [-N nflows] [-o outfile_basename] [-T nseconds] [-z z_level] DESCRIPTION
The flow-split utility will split a flow file into smaller files based on the the number of flows or the ammount of time that has passed. OPTIONS
-b big|little Byte order of output. -C Comment Add a comment. -d debug_level Enable debugging. -g Split on source tag. -G Split on destination tag. -h Display help. -n Use symbols for tag field in filename. -N nflows Split after processing nflows. -o outfile_basename The basename of the resulting files. -T nsecond Split after processing an interval of nseconds flows. -z z_level Configure compression level to z_level. 0 is disabled (no compression), 9 is highest compression. EXAMPLES
Create 1 minute flow files from the flow archive in /flows/krc4. Store the results in /flows/krc4.split flow-cat /flows/krc4 | flow-split -T60 -o /flows/krc4.split/1min. BUGS
None known. AUTHOR
Mark Fullmer maf@splintered.net SEE ALSO
flow-tools(1) flow-split(1)
All times are GMT -4. The time now is 10:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy