Create new file with increment column based on conditions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create new file with increment column based on conditions
# 1  
Old 10-23-2014
Bug Create new file with increment column based on conditions

Hello,

Using bash script, i need to process the following file:

887,86,,2013-11-06,1,10030,5,2,0,200,,
887,86,,2013-11-05,1,10030,5,2,0,199,,
887,138,,2013-11-06,1,10031,6,2,0,1610612736,,
887,164,,2013-11-06,1,10000,0,2,0,36000,,

and to create a new file such as the below

887,100,200,86
887,101,199,86
887,100,1610612736,138
887,100,36000,164.

The main functionality would be to check whether column 1 and 2 are indentical (in the example that's 887 and 86). If this is the case, then the second field on the new file will be an incremental value starting from 100 for the first match row and 101 for the second and so on. If no more that one matching rows on 1 and 2 are found ,then the value of the new second row would be 100.

Can you please help?

Thanks,
John
# 2  
Old 10-23-2014
Can you post what you have done to solve this problem...
# 3  
Old 10-23-2014
Is this a homework assignment?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to update file based on 5 conditions

I am trying to use awk to update the below tab-delimited file based on 5 different rules/conditions. The final output is also tab-delimited and each line in the file will meet one of the conditions. My attemp is below as well though I am not very confident in it. Thank you :). Condition 1: The... (10 Replies)
Discussion started by: cmccabe
10 Replies

2. Shell Programming and Scripting

Increment Column having Alphanumeric value in file

I want to replace a column(first and last) having an alphanumeric value in a file. Requirement : 1)All values in a Column must be unique and contain an incremented pattern “HCTV0096” for first column and “cafefeca0090” for last column 2)for uniquely identifying each value in column Numeric part... (6 Replies)
Discussion started by: ketanraut
6 Replies

3. Shell Programming and Scripting

Help with Creating file based on conditions

Can anyone please assist? I have a .txt file(File1.txt) and a property file(propertyfile.txt) . I have to read the vales from the property file and .txt file and create the output file(outputfile.txt) mentioned in the attachment. For each record in .txt file,the below mentioned values shall be... (20 Replies)
Discussion started by: vinus
20 Replies

4. Shell Programming and Scripting

Split File based on different conditions

I need to split the file Conditions: Ignore any record that either starts with 1 or 9 Split the file at position 404 , if position 404 is abc or def then write all the records in a file > File 1 , the remaining records should go in to a file > File 2 Further I want to split the... (7 Replies)
Discussion started by: protech
7 Replies

5. Shell Programming and Scripting

Increment existing column in file

Hi All, I have a file with 3 millions records in which 3rd column is same throughout say its value is 0 throughout.for example: Col1 Col2 Col3 Col4 A 1 0 5 B 2 0 6 C 3 0 7 D 4 0 9 I want my output as : Col1 Col2 Col3 Col4 A 1 ... (4 Replies)
Discussion started by: Pinky456
4 Replies

6. Shell Programming and Scripting

Deleting values in a column based on conditions

Hi I have a difficulty in writing shell script for performing the tasks. A B C D 12 230 16 259 18 260 23 283 21 291 36 298 41 309 49 420 52 425 57 450 61 456 70 473 72 475 79 486 If the A(row no.2) < C(row no.1) then delete value A(row no.1) and so on... For... (8 Replies)
Discussion started by: Sarwagya Jha
8 Replies

7. Shell Programming and Scripting

Create files based on second column of a file

Hi All, I have a file which looks like this: 234422 1 .00222 323232 1 3232 32323 1 0.00222 1234 2 1211 2332 2 0.9 233 3 0.883 123 3 45 As you can see, the second column of the file is already sorted which I did using sort command. Now, I want to create files based on the second... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. UNIX for Dummies Questions & Answers

How to get remove duplicate of a file based on many conditions

Hii Friends.. I have a huge set of data stored in a file.Which is as shown below a.dat: RAO 1869 12 19 0 0 0.00 17.9000 82.3000 10.0 0 0.00 0 3.70 0.00 0.00 0 0.00 3.70 4 NULL LEE 1870 4 11 1 0 0.00 30.0000 99.0000 0.0 0 0.00 0 0.00 0.00 0.00 0 ... (3 Replies)
Discussion started by: reva
3 Replies

9. Shell Programming and Scripting

create pipes based on the column

i get text files with Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3 Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|4 Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26 23:59:00|Deactivated|6 Based... (3 Replies)
Discussion started by: ramse8pc
3 Replies

10. Shell Programming and Scripting

validating a file based on conditions

i have a file in unix in which the records are like this aaa 123 233 aaa 234 222 aaa 242 222 bbb 122 111 bbb 122 123 ccc 124 222 In the output i want only the below records aaa ccc The validation logic is 1st column and 2nd column need to be considered if both columns values are... (8 Replies)
Discussion started by: trichyselva
8 Replies
Login or Register to Ask a Question