Visit The New, Modern Unix Linux Community


Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces
# 1  
Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space.
Total length of record is 420. Here is the specification of the data in file.
Code:
Position    Field Data Type
-----------------------------------------------------
1          Capital Letter total length = 1
2-6          Blanks
7-15         Numeric Data total length 9
16-19       Numeric Data total length 4
20-25       Year and Month.
26-31        Blanks
32           Character Data total length 1
33           Character Data total length 1
34-41        Blanks
42-43        Character Data total length 2
44-48        Blanks
49          Capital Letter total length = 1
50-89          Character total 39 length
90-129        Character total 39 length 
130          Capital Letter total length = 1
131-170          Character Data total length 39
171-199         Alphabetic Data total length 29
200-201         Character Data total length 2
202-210         Numeric Data total length 5
211-219         Numeric Data total length 9
220-290         Character Data total length 60
291-330          Character Data total length 39
331-359       Alphabetic total length 29 character 
360-361       Character Data total length 2
362-370       Numeric Data total length 5
371           Capital Letter total length = 1
372-420         Blanks

Any help on this will be appreciated. Thanks in advance.

Last edited by lancesunny; 10-03-2012 at 11:07 AM.. Reason: Code tags
# 2  
Quote:
Originally Posted by lancesunny
Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space.
Total length of record is 413.

Before:
RR 201 123456789 00599 0001230111 +00000000123 XXX 100111......123456789 ..............................................................................1
SS 201 00456 00599 0001230111 +00000000123 XXX 100222......12345..............................................................................2
TT 201 234567890 00599 0001230111 +00000000123 ABC 100333......234567890 ..............................................................................3

Hoping for After:
RR 201 123456789 00599 0001230111 +00000000123 XXX 100111...... ..............................................................................1
SS 201 00456 00599 0001230111 +00000000123 XXX 100222......12345..............................................................................2
TT 201 234567890 00599 0001230111 +00000000123 ABC 100333...... ..............................................................................3

where
1st Record position 7-15 & 211-219 Value=123456789 are matching and therefore we need to replace position 211-219 with 9 space characters
1st Record position 7-15 & 211-219 Value=234567890 are matching and therefore we need to replace position 211-219 with 9 space characters.

Any help on this will be appreciated.
Thanks in advance.
Please use code tags when showing input and output strings. You say that the total record length of each of your input and output records is 413, but the three input records you have given us contain 152, 143, and 152 bytes, respectively (not counting the terminating <newline> character) and each of your three output records contain 143 bytes.

You also give two conflicting descriptions of what is in the 1st record.

Making a guess at what your input really looks like, the following may work:
Code:
awk '{if(length() > 220 && substr($0,7,9) == substr($0,211,9))
                printf("%s         %s\n", substr($0,1,210), substr($0,220))
        else    print}' input

# 3  
Guys I've updated the code tags with specs for more detailed info.
Thanks for you help. Sorry for the typo and confusion.
# 4  
# 5  
Like this (not tested)?
Code:
awk 'substr($0,7,9)==substr($0,211,9){
$0=substr($0,1,210) sprintf("%9s",x) substr($0,220)
}1' file

This User Gave Thanks to elixir_sinari For This Post:
# 6  
Thanks elixir_sinari.
Your code worked fine.
Thanks a lot for your help & time on this.Smilie

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #99
Difficulty: Easy
Unix has a flat file structure which allows easier access and maintenance of data.
True or False?

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

if characters from positions 7-15 are matching 219 then replace al

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space. Total length of record is 420. Here is the specification of the data in file. Position Field Data Type... (2 Replies)
Discussion started by: lancesunny
2 Replies

2. Homework & Coursework Questions

POS 420 Week 4 IA

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: <LI style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in" class=MsoNormal>In your week4... (0 Replies)
Discussion started by: smiley76112
0 Replies

3. What is on Your Mind?

This Weeks Lottery - Jackpot Now 219,500 Bits

If you want to win some Bits, the jackpot for tomorrow's drawing is up to 219,500 Bits Lottery tickets are only 100 Bits :D (0 Replies)
Discussion started by: Neo
0 Replies

Featured Tech Videos