Visit Our UNIX and Linux User Community


append the position 28:33


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting append the position 28:33
# 1  
Old 11-06-2009
I have a file FILE1.DAT like below

21111111110001343 000001004OLF-AA029100020091112
21111111110000060 000001004ODL-CH001000020091112
24444444440001416 000001045OLF-AA011800020091112
23333333330001695 000001039OLF-AA030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
22222222220000780 000001013OLF-AA006500020091112

i like to append the values only for the position 28:33
OLF-AA to OLF-1E
ODL-SP to ODL-2S
ODL-CH to ODL-3C

21111111110001343 000001004OLF-1E029100020091112
21111111110000060 000001004ODL-3C001000020091112
24444444440001416 000001045OLF-1E011800020091112
23333333330001695 000001039OLF-1E030600020091112
23333333330000111 000001039ODL-2S002000020091112
23333333330000060 000001039ODL-3C001000020091112
22222222220000780 000001013OLF-1E006500020091112

This i want in .KSH script, thanks in advance.

i have the following data in the FILE1

21111111110000204 000029148OLF-AA006300020091112
22222222220004038 000002304OLF-AA012500020091112 0003231 0000060
23333333330003265 000002315OLF-AA039300020091112 0000415
24444444440001344 000009896OLF-AA011200020091112 0000120
25555555550001778 000002331OLF-AA021400020091112
26666666660001098 000002336OLF-AA003400020091112 0000969
27777777770002653 000002349OLF-AA047900020091112
28888888880000636 000026198OLF-AA005300020091112
29999999990000244 000029309OLF-AA004800020091112
21231231230001440 000010268OLF-AA012000020091112 0001200
24564564560004404 000002368OLF-AA020300020091112

i like to append only those line having empty space for the position 50-56 & 58-64 with 7 zeros 0000000 (eg: record line 7, 8 & 9)

the outfile FILE2.txt should be like this

21111111110000204 000029148OLF-AA006300020091112 0000000 0000000
22222222220004038 000002304OLF-AA012500020091112 0003231 0000060
23333333330003265 000002315OLF-AA039300020091112 0000415 0000000
24444444440001344 000009896OLF-AA011200020091112 0000120 0000000
25555555550001778 000002331OLF-AA021400020091112 0000000 0000000
26666666660001098 000002336OLF-AA003400020091112 0000969 0000000
27777777770002653 000002349OLF-AA047900020091112 0000000 0000000
28888888880000636 000026198OLF-AA005300020091112 0000000 0000000
29999999990000244 000029309OLF-AA004800020091112 0000000 0000000
21231231230001440 000010268OLF-AA012000020091112 0001200 0000000
24564564560004404 000002368OLF-AA020300020091112 0000000 0000000

this i like to have in .KSH script

thxs in adv.

Last edited by vbe; 11-06-2009 at 03:00 PM..
# 2  
Old 11-06-2009
Code:
sed 's/OLF-AA/OLF-1E/;s/ODL-SP/ODL-2S/;s/ODL-CH/ODL-3C/' infile

# 3  
Old 11-06-2009
See:
https://www.unix.com/shell-programmin...#post302367859

Same user with total disrespect of forum rules: banned

Previous Thread | Next Thread
Test Your Knowledge in Computers #946
Difficulty: Medium
A ping flood attack is a simple DOS attack where the attacker overwhelms the victim with TCP echo request packets.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting value at a particular position without changing the position of other characters

Hi All, I wanted a sed/awk command to add a value/character on a particular position without disturbing the position of other characters. I have file a.txt OL 10031 Day Black Midi Good Value P01 P07 OL 10031 Day Black Short Good Value P01 P07 I want to get the output as... (2 Replies)
Discussion started by: rahulsk
2 Replies

2. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

3. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

Remove text from n position to n position sed/awk

I want to remove text from nth position to nth position couple of times in same line my line is "hello is there anyone can help me with this question" I need like this ello is there anyone can help me with question 'h' is removed and 'this' removed from the line. I want to do this... (5 Replies)
Discussion started by: elamurugu
5 Replies

5. Shell Programming and Scripting

Moving first position in a file to the last position

hi, I have a file which consists of some records: 2010_06_4010093_001_001|10|ABCDEFGH|9|4010093||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00001| 2010_06_4010162_001_001|11|ABCDEFGH|9|4010162||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00002|... (11 Replies)
Discussion started by: pparthiv
11 Replies

6. Shell Programming and Scripting

append each line on fixed position 31 to 33

I have a .DAT file like below. 26666666660001343 000001004OLF 029100020090820 27777777770000060 000001004ODL-CH001000020090820 28888888880000780 000001013OLF 006500020090820 ....... ........ and so on..... I want to append each line in a file in .KSH script with XXX with position... (5 Replies)
Discussion started by: kshuser
5 Replies

7. Shell Programming and Scripting

append existing file with zeroes bsed on position

Hi i am trying to append value with 0 to an existing file in the position 50-56 & 58-64 only where empty space is there Rule: 1 row already has some value and i do not want to change anything for this row. 2nd record below you see the position 50-64 is empty, i want to replace with 0000000... (3 Replies)
Discussion started by: kshuser
3 Replies

8. UNIX for Dummies Questions & Answers

find if a position is between a given start and end position

Hi, I am a newbie in unix programming so maybe this is a simple question. I would like to know how can I make a script that outputs only the values that are not between any given start and end positions Example file1: 2 30 40 80 82 100 file2: ID1 1 ID2 35 ID3 80 ID4 81 ID6... (9 Replies)
Discussion started by: fadista
9 Replies

9. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

10. Shell Programming and Scripting

Append line based on fixed position

Hi all; I'm having headache on append one line to another based on the fix position.Hope u guys can help. All i need to do is append the line that start with '3' to a line which start with '1' and the position for line 3 that i need to append is 22. The original file look like this: ... (2 Replies)
Discussion started by: ashikin_8119
2 Replies

Featured Tech Videos