Sponsored Content
Top Forums Shell Programming and Scripting Combine and complete multiple CSV files based on 1 parameter Post 303021909 by RudiC on Monday 20th of August 2018 11:25:12 AM
Old 08-20-2018
OK, now that everthing is more or less clear, let's try
Code:
awk -F, '
FNR == 1        {FLNR++
                 FN[FLNR] = FILENAME
                 next
                }

                {V[FLNR, $2] = $3
                 D[FLNR, $2] = $4
                 if ($2 > MX2) MX2 = $2
                }

END             {print "Source,Well_Source,Volume,Destination_Well,Destination"
                 for (f=1; f<=FLNR; f++)
                   for (i=1; i<=MX2; i++)       {ft = f
                                                 while ((ft <= FLNR) && (V[ft,i] == 0)) ft++
                                                 if (ft > FLNR) ft = f
                                                 print FN[ft], i, V[ft,i], D[f,i], "Deadpool"
                                                 V[ft, i] = 0
                                                }
                }

'  OFS=, Input[1-4]
Source,Well_Source,Volume,Destination_Well,Destination
Input1,1,5,1,Deadpool
Input1,2,7,1,Deadpool
Input1,3,8,1,Deadpool
Input1,4,3,1,Deadpool
Input1,5,5,1,Deadpool
Input1,6,0,1,Deadpool
Input1,7,4.,1,Deadpool
Input1,8,7.1,1,Deadpool
Input2,9,10,1,Deadpool
Input4,10,10,1,Deadpool
Input3,1,5,1,Deadpool
Input2,2,0,1,Deadpool
Input2,3,8,1,Deadpool
Input2,4,3,1,Deadpool
Input2,5,5,1,Deadpool
Input2,6,0,1,Deadpool
Input2,7,4.,1,Deadpool
Input2,8,7.1,1,Deadpool
Input3,9,10,1,Deadpool
Input2,10,0,1,Deadpool
Input4,1,5,1,Deadpool
Input3,2,0,1,Deadpool
Input3,3,8,1,Deadpool
Input4,4,5,1,Deadpool
Input4,5,5,1,Deadpool
Input3,6,0,1,Deadpool
Input3,7,4.,1,Deadpool
Input3,8,7.1,1,Deadpool
Input4,9,10,1,Deadpool
Input3,10,0,1,Deadpool
Input4,1,0,1,Deadpool
Input4,2,0,1,Deadpool
Input4,3,8,1,Deadpool
Input4,4,0,1,Deadpool
Input4,5,0,1,Deadpool
Input4,6,0,1,Deadpool
Input4,7,4.,1,Deadpool
Input4,8,7.1,1,Deadpool
Input4,9,0,1,Deadpool
Input4,10,0,1,Deadpool

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to combine 2 lines in same files based on any text

hi, I want to combine two lines in same file. If the line ends with '&' it should belongs to previous line only Here i am writing example. Ex1: line 1 : return abcdefgh& line 2 : ijklmnopqr& line 3 : stuvw& line 4 : xyz output should be line 1: return abcdefghijklmnopqrstuvwxyz ... (11 Replies)
Discussion started by: spc432
11 Replies

2. Shell Programming and Scripting

Combine Multiple text or csv files column-wise

Hi All I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below. What can i do to resolve this ? File 1 File... (15 Replies)
Discussion started by: venky_ibm
15 Replies

3. Shell Programming and Scripting

Combine two files and put it in .csv file

Hi Freinds I have two .txt file gem1.txt and gem2.txt, Sample gem1.txt abstract (1.0.0) actionmailer (2.3.5, 2.2.2) actionpack (2.3.5, 2.2.2) activerecord (2.3.5, 2.2.2) activerecord-oracle_enhanced-adapter (1.1.9) activerecord-sqlserver-adapter (2.3.4) activeresource (2.3.5, 2.2.2)... (3 Replies)
Discussion started by: ankit_view24
3 Replies

4. Shell Programming and Scripting

How to combine two files based on fields?

I have two files which are as follows: File 1: 1 abc 250 2 pqr 300 3 xyz 100 File 2: 1 abc 230 2 pqr 700 3 xyz 500 Now I need output File, File 3as: S.No Name Count1 Count2 1 abc 250 230 2 pqr 300 700 3 xyz 100 500 NOTE: (13 Replies)
Discussion started by: karumudi7
13 Replies

5. Shell Programming and Scripting

combine lines from two files based on an if statement

I'm rather new to programming, and am attempting to combine lines from 2 files in a way that is way beyond my expertise - any help would be appreciated! I need to take a file (file1) and add columns to it from another file (file2). However, a line from file2 should only be added to a given line... (3 Replies)
Discussion started by: Cheri
3 Replies

6. Shell Programming and Scripting

Combine multiple lines in file based on specific field

Hi, I have an issue to combine multiple lines of a file. I have records as below. Fields are delimited by TAB. Each lines are ending with a new line char (\n) Input -------- ABC 123456 abcde 987 890456 7890 xyz ght gtuv ABC 5tyin 1234 789 ghty kuio ABC ghty jind 1234 678 ght ... (8 Replies)
Discussion started by: ratheesh2011
8 Replies

7. Shell Programming and Scripting

Combine 3 files based on a pattern

HI, I have 3 files that contain the following information (sql output from Oracle database stored in a txt file): File1.txt : alter table "SYS"."INT_COST_PRICE" enable row movement; alter table "SYS"."INT_SOH" enable row movement; alter table "SYSMAN"."XX_ACI_SKURTP" enable row movement;... (6 Replies)
Discussion started by: rparavastu
6 Replies

8. Shell Programming and Scripting

Awk: Combine multiple lines based on number of fields

If a file has following kind of data, comma delimited 1,2,3,4 1 1 1,2,3,4 1,2 2 2,3,4 My required output must have only 4 columns with comma delimited 1,2,3,4 111,2,3,4 1,222,3,4 I have tried many awk command using ORS="" but couldnt progress (10 Replies)
Discussion started by: mdkm
10 Replies

9. Shell Programming and Scripting

Combine multiple rows based on selected column keys

Hello I want to collapse a file with multiple rows into consolidated lines of entries based on selected columns as the 'key'. Example: 1 2 3 Abc def ghi 1 2 3 jkl mno p qrts 6 9 0 mno def Abc 7 8 4 Abc mno mno abc 7 8 9 mno mno abc 7 8 9 mno j k So if columns 1, 2 and 3 are... (6 Replies)
Discussion started by: linuxlearner123
6 Replies

10. Shell Programming and Scripting

CSV File with Multiple Search Parameter

Dear Team Members, I have a unique problem. Below is the dataset which I have. I am writing a script which will read through the file and pull the invoice no. (Field 2 of C1 row). "C1",990001,"L1","HERO","MOTORCYCLE","ASIA-PACIFIC","BEIJING" "C2","CLUTCH","HYUNDAI",03032017... (13 Replies)
Discussion started by: chetanojha
13 Replies
flow-gen(1)						      General Commands Manual						       flow-gen(1)

NAME
flow-gen -- Generate test flows SYNOPSIS
flow-gen [-h] [-b big|little] [-d debug_level] [-n count] [-V version] [-z z_level] DESCRIPTION
The flow-gen utility generates a test pattern of flows in any of the currently supported export versions typically for debugging purposes. OPTIONS
-b big|little Byte order of output. -d debug_level Enable debugging. -h Display help. -n count Generate count flows. Default 1000. -V version Generate version type exports. Supported versions are: 1 NetFlow version 1 (No sequence numbers, AS, or mask) 5 NetFlow version 5 6 NetFlow version 6 (5+ Encapsulation size) 7 NetFlow version 7 (Catalyst switches) 8.1 NetFlow AS Aggregation 8.2 NetFlow Proto Port Aggregation 8.3 NetFlow Source Prefix Aggregation 8.4 NetFlow Destination Prefix Aggregation 8.5 NetFlow Prefix Aggregation 8.6 NetFlow Destination (Catalyst switches) 8.7 NetFlow Source Destination (Catalyst switches) 8.8 NetFlow Full Flow (Catalyst switches) 8.9 NetFlow ToS AS Aggregation 8.10 NetFlow ToS Proto Port Aggregation 8.11 NetFlow ToS Source Prefix Aggregation 8.12 NetFlow ToS Destination Prefix Aggregation 8.13 NetFlow ToS Prefix Aggregation 8.14 NetFlow ToS Prefix Port Aggregation 1005 Flow-Tools tagged version 5 -z z_level Configure compression level to z_level. 0 is disabled (no compression), 9 is highest compression. EXAMPLES
Generate a test pattern of 1000 version 5 flows and send them in the Cisco NetFlow packet format to 10.0.0.1 port 9500. flow-gen -V5 | flow-send 0/10.0.0.1/9500 BUGS
The test pattern may change between releases. AUTHOR
Mark Fullmer maf@splintered.net SEE ALSO
flow-tools(1) flow-gen(1)
All times are GMT -4. The time now is 06:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy