Change file content based on data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change file content based on data
# 1  
Old 08-18-2010
Change file content based on data

I have a Transaction File coming into the system. In this file, in all records the relevant data is as follows-

Position 1:10 -> Transaction Code
Position 252:255 -> 4 digit business code

Now based on these 2 fields I have to alter value in Transaction code (Position 1:10)
Code:
For example if  10 digit transaction code is “CN0001N  -“  and 
4 digit business code is one of following values  0292, 0379, 1038, 7810, 7811, 7812, 7842, 7843 
change the 10 digit transaction code to “CNQCSHN  -“



I have to check for 15 similar conditions.

Also My file is having lots of records - (Around 1 Million) so performance is also an issue.

Could someone please suggest the approach which should be taken for this?
# 2  
Old 08-18-2010
not clear.

provide sample input file and output file here.
# 3  
Old 08-18-2010
detailed explanation

I hope the below explanation will make the things clears. As the single record in file is having 955 characters, file is too big to be posted even for sample record.


Input file Details

Position 1:10 -> Transaction Code
Position 252:255 -> 4 digit business code

Condition


IF

10 digit transaction code = “CN0001N -“
( from position 1:10)

4 digit business code = One from following -> 0292, 0379,
1038, 7810, 7811, 7812, 7842, 7843

THEN

Change the 10 digit transaction code(position 1:10) to “CNQCSHN -“
# 4  
Old 08-18-2010
Ok, for my understanding, the input should be like (just a sample)

Code:
Position 1:10 -> CN0001N -
Position 252:255 -> 0292

then the output will be:

Code:
Position 1:10 -> CNQCSHN -
Position 252:255 -> 0292

is it right?
# 5  
Old 08-18-2010
Your understanding is totally corect

Yes. This is exactly what is required.

Also there are around 1 million records in the file and the command/script should check all records.

And there are 15 similar conditions.
# 6  
Old 08-18-2010
give some samples from your real date for us to easily understand. For example, how to identify there are four records? split by empty lines or other condition?

Such as: ?

Code:
Position 1:10 -> CN0001N -
Position 252:255 -> 0292

Position 1:10 -> CN0001N -
Position 252:255 -> 0292

Position 1:10 -> CN0002N -
Position 252:255 -> 0379

Position 1:10 -> CN0001N -
Position 252:255 -> 0292

# 7  
Old 08-18-2010
Are you looking for something like this.

Code:
$ cat 1.txt
Position 1:10 -> CN0001N -
Position 252:255 -> 0292

Position 1:10 -> CN0001N -
Position 252:255 -> 7810

Position 1:10 -> CN0002N -
Position 252:255 -> 0111

Position 1:10 -> CN0001N -
Position 252:255 -> 0292

Code:
awk -F "->" '{
       if($1 == "Position 1:10 ")
       {
          line1=$0;
          getline;
          if($2==0292 || $2==0379 || $2==1038 || $2==7810|| $2==7811|| $2==7812|| $2==7842|| $2==7843)
             line1="Position 1:10 -> CNQCSHN -";
          print line1;
          print;
       }
       else print;
    }' 1.txt

Code:
Output:
Position 1:10 -> CNQCSHN -
Position 252:255 -> 0292

Position 1:10 -> CNQCSHN -
Position 252:255 -> 7810

Position 1:10 -> CN0002N -
Position 252:255 -> 0111

Position 1:10 -> CNQCSHN -
Position 252:255 -> 0292

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to change the file content using some conditions

Hello, I would like to change the content of the file that has few blocks starts with 10 and ends with ";" File1.txt 10 bonuses D 20 MATCHED 30 UPD COL 40 (SOL=30) 20 NOT MATCHED 30 INS COL 40 (SOL=30) ; 10 bonuses D 20 MATCHED 30 UPD COL 40... (5 Replies)
Discussion started by: Mannu2525
5 Replies

2. Shell Programming and Scripting

Change a file content format using awk

Hi, i have a file input.txt Continent North America Country USA Capital Washington D.C. Country Canada Capital Ottawa Continent South America Country Argentina Capital Buenos Aires Country Brazil Capital Brasília Coutry Colombia Capital Bogotá and i want to get an output.txt ... (3 Replies)
Discussion started by: fastlane3000
3 Replies

3. Shell Programming and Scripting

Help with data rearrangement based on share same content

Input file data_2 USA data_2 JAPAN data_3 UK data_4 Brazil data_5 Singapore data_5 Indo data_5 Thailand data_6 China Desired output file data_2 USA/JAPAN data_3 UK data_4 Brazil data_5 Singapore/Indo/Thailand data_6 China I would like to merge all data content that share same... (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

Help with analysis data based on particular column content

Input file: Total_counts 1306726155 100% Number_of_count_true 855020282 Number_of_count_true_1 160014283 Number_of_count_true_2 44002825 Number_of_count_true_3 18098424 Number_of_count_true_4 24693745 Number_of_count_false 115421870 Number_of_count_true 51048447 Total_number_of_false ... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

6. Linux

when SCP, does file content change?

Good day to you all, Just want to check here, i know when scping a file, size might change due to space issue. it might sound silly, but does file content get change too? if so, what kind of situation that might be? (1 Reply)
Discussion started by: ahtat99
1 Replies

7. Shell Programming and Scripting

Execution Problems with scan and change file data content

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXAXXXXGXXA . . Desired output file >Read_1 XXXXXXXXXXXXXXXXXXDS ASDRXXXXXTGAGTXXXXXT TGTGATXXXXXXXXXXXXXA . . (5 Replies)
Discussion started by: patrick87
5 Replies

8. Shell Programming and Scripting

Scan and change file data content problem

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X") TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter,... (12 Replies)
Discussion started by: patrick87
12 Replies

9. Shell Programming and Scripting

How to change a file's content by row?

Greetings. So the question is basically the same as it's in the title. I'd like to write a program that changes a file by rows. So to clarify it. (i know i shouldn't use code,/code here but i would like to separate it) So for example a text file looks like something like this: Happy... (5 Replies)
Discussion started by: buddhist
5 Replies

10. UNIX for Advanced & Expert Users

Need help to change the content for remote located file

Hi All, I have one file that sits on 4 diffrent servers, those servers are diffrent region based and they are authentication protected and that file has a diff port numbers, so when run the script it must ask my login details,region of server and port no for that file once it took from me... (1 Reply)
Discussion started by: tmarjuna
1 Replies
Login or Register to Ask a Question