File merging based on different counter loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File merging based on different counter loop
# 1  
Old 03-26-2012
File merging based on different index counter

hello,

File 1
Code:
main Group            sub group
    MIT               VAR_1D_DATA_TYPE      23-03-2012
    MIT               VAR_1D_DATA_TYPE      22-03-2012

   MIT              VAR_10D_DATA_TYPE      23-03-2012
   MIT              VAR_10D_DATA_TYPE      22-03-2012

   MIT      STRESSED_VAR_1D_DATA_TYPE      23-03-2012
   MIT      STRESSED_VAR_1D_DATA_TYPE      22-03-2012

   MIT     STRESSED_VAR_10D_DATA_TYPE      23-03-2012
   MIT     STRESSED_VAR_10D_DATA_TYPE      22-03-2012

   ISS               CB_VAR_DATA_TYPE      23-03-2012
   ISS               CB_VAR_DATA_TYPE      22-03-2012

file 2
Code:
index		value
0		42379
1		1349
2		234
3		789
4		456
5		7634
6		879
7		5890
8		3210
9		87540
10		65430
11		879
12		2156
13    	658
14		87985
15		896
16		542
17		635

op file

Code:
main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13

   ISS               CB_DATA_TYPE      23-03-2012	16
   ISS               CB_DATA_TYPE      22-03-2012	17

It's a strange requirement ,
first of all, main role are played by individual main groups and sub groups.
here in this example it's 2
and then how many sub groups are there under each main group
here e.g. for MIT there are 4 sub groups are present 1D_DATA_TYPE,10D_DATA_TYPE, STRESSED_1D_DATA_TYPE,STRESSED_10D_DATA_TYPE
similarly for ISS only one sub group is present i.e. CB_DATA_TYPE

so it will now check file 2 for values, I have mentioned index number for more readbility.
index counter always begin from nr.3 then it will check next sub-group, if it is same sub group as well as main group then it increase the index counter next one +1.

if it's new subgroup, then it will check the main group, if it's same then then index counter will increase by +2 from the previous one, and then it will again check for the next subgroup and taking consideration of previous main and sub group.

let say next sub group is a new sub group as well as a new main group then counter will increase by +3 from the previous one. same loop goes thru all over file 1 and corresponding index value will be printed.

e.g. STRESSED_10D_DATA_TYPE index counter is 13 ,
now checks for next sub group found that it's new sub group as well as new main group so the index counter increased to 16. (+3)
let say it found another same STRESSED_10D_DATA_TYPE sub group with same main group then next index would be 14 (+1)
then it encounters CB_DATA_TYPE index for ISS , index would be 17(+3) as previous one was 14.

let say it found another new sub group but main group reamins same, then index counter for that new sub group 15 (+2)
then it encounters CB_DATA_TYPE index for ISS , index would be 18(+3) as previous one was 15.

This rule applied for the whole file1 after the first line indexed.
how can I achieve this one???

have a look on different o/p on different scenario

Scenario 1 o/p
Code:
main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13
   MIT     STRESSED_10D_DATA_TYPE      12-03-2012	14

   ISS               CB_DATA_TYPE      23-03-2012	17
   ISS               CB_DATA_TYPE      22-03-2012	18

scenario 2 o/p
Code:
main Group            sub group				index
    MIT               1D_DATA_TYPE      23-03-2012	3
    MIT               1D_DATA_TYPE      22-03-2012	4

   MIT              10D_DATA_TYPE      23-03-2012	6
   MIT              10D_DATA_TYPE      22-03-2012	7

   MIT      STRESSED_1D_DATA_TYPE      23-03-2012	9
   MIT      STRESSED_1D_DATA_TYPE      22-03-2012	10

   MIT     STRESSED_10D_DATA_TYPE      23-03-2012	12
   MIT     STRESSED_10D_DATA_TYPE      22-03-2012	13

   MIT     	    ED_10D_DATA_TYPE      12-03-2012	15

   ISS               CB_DATA_TYPE      23-03-2012	18
   ISS               CB_DATA_TYPE      22-03-2012	19


Last edited by manas_ranjan; 03-30-2012 at 05:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counter based on 10 files or less

there are around 676 files in a directory and I want to batch every 10 and then remaining 7 files as well for a batch pressing job simultaneously. I'm trying to pick-up every 10 counter'd files -- batch these files and then move on with the next batch.. after resetting the Counters back to 0; ... (5 Replies)
Discussion started by: busyboy
5 Replies

2. UNIX for Dummies Questions & Answers

File merging based on column patterns

Hello :) I am in this situation: Input: two tab-delimited files, `File1` and `File2`. `File2` (`$2`) has to be parsed by patterns found in `File1` (`$1`). Expected output: tab-delimited file, `File3`. `File3` has to contain the same rows as `File2`, plus the corresponding value in... (5 Replies)
Discussion started by: dovah
5 Replies

3. Shell Programming and Scripting

Merging two file based on comparison of first columns

Respected Members. Hello. This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them. I am working on two files. I wish to merge the two files... (6 Replies)
Discussion started by: manojmalhotra
6 Replies

4. Shell Programming and Scripting

Merging two file based on comparison of first columns

Respected Members. Hello. This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them. I am working on two files. I wish to merge the two files... (1 Reply)
Discussion started by: manojmalhotra
1 Replies

5. UNIX for Dummies Questions & Answers

Loop for file merging in a folder

Dear all, I have a few files in a folder (lets say 5) and each have a few lines in them. I want to create merges of each of them with the other ones e.g. I need the following merges I tried to write a loop and started with combinations of 2, I get the write file names but for each... (17 Replies)
Discussion started by: A-V
17 Replies

6. Shell Programming and Scripting

Help on Adding one counter loop at the end of each line in a file

Hello All, I have file a.txt I want to add a counter loop at the end of each line in a file ill explain: i have a site h**p://test.test=Elite#1 i want to add a a counter to the number at the end of the file, that it will be like this urlLink//test.test=Elite#1 urlLink//test.test=Elite#2... (3 Replies)
Discussion started by: nexsus
3 Replies

7. Homework & Coursework Questions

Min/Max/counter/while loop from file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The program is supposed to read in text from a given file ( different samples provided in the homework but not... (1 Reply)
Discussion started by: c++newb
1 Replies

8. Shell Programming and Scripting

S# in a for loop - concatenate $(loop counter)

Hi, hope I am posting in the right section. My problem is that I have 2 or more arguments passed and I want to check if the arguments passed exists or not. The first argument should not exist and the remaining others should exist. example: ./shells.sh argument1 argument2 argument3 ... (5 Replies)
Discussion started by: fight4love
5 Replies

9. UNIX for Dummies Questions & Answers

Merging two files based on two columns to make a third file

Hi there, I'm trying to merge two files and make a third file. However, two of the columns need to match exactly in both files AND I want everything from both files in the output if the two columns match in that row. First file looks like this: chr1 10001980 T A Second... (12 Replies)
Discussion started by: infiniteabyss
12 Replies

10. Shell Programming and Scripting

Merging lines based on occurances of a particular character in a file

Hi, Is there any way to merge two lines based on specific occurance of a character in a file. I am having a flat file which contains multiple records. Each row in the file should contain specified number of delimiter. For a particular row , if the delimiter count is not matched with... (2 Replies)
Discussion started by: mohan_tuty
2 Replies
Login or Register to Ask a Question