General
cancel
Showing results for 
Search instead for 
Did you mean: 

Place 2 digit letter in a file at particular place

pk1974
Occasional Contributor

Place 2 digit letter in a file at particular place

Hi

Can anyone help me to place a code of 2 digits from a file and place into another file at a particular position
10 REPLIES
Bob E Campbell
Honored Contributor

Re: Place 2 digit letter in a file at particular place

Sure, but you will need to give us more information. Is this binary data? Is the position determined by offsets or data? By two digit letter do you mean a single multi-byte character?

Example file snippets would make this a simple matter for many in the forums.
Dennis Handly
Acclaimed Contributor

Re: Place 2 digit letter in a file at particular place

Do you want to insert or replace the 2 chars?
Is it a particular position in every record or in one place in the file?
PK_1975
Frequent Advisor

Re: Place 2 digit letter in a file at particular place

thanks for ur reply

for everyfile we have to place a 2 digit code like"01" at position 31 and 32 at line 1
Bob E Campbell
Honored Contributor

Re: Place 2 digit letter in a file at particular place

If you mean to do an insert try:

sed -e "1 s/\(.\{32\}\)/\1XX/" < YourFile

And if you meant to replace try:

sed -e "1 s/\(.\{30\}\)../\1XX/" < YourFile
PK_1975
Frequent Advisor

Re: Place 2 digit letter in a file at particular place

That one is not working, please check my request

This is line number 1

00XXXXXXXXXX20081110XXXXXXXXXX00TT1

I want to place 45 after TT1 that position is 35 and 36

after placing it should be look like this

00XXXXXXXXXX20081110XXXXXXXXXX00TT145

could you please help me
Bob E Campbell
Honored Contributor

Re: Place 2 digit letter in a file at particular place

Thought I would decipher this for you.

# sed -e "1 s/\(.\{30\}\)../\1XX/" < temp

"1" - This is the line to edit. It can be given a specific number, a range "2,7" or a pattern to match "/Customer/".

".\{30\}" - This will match any 30 characters and will work for our use. If we put a "^" at the start it would lock it to the first 30 characters on the line.

"\( \)" - These tell sed to remember the characters matched for use in the replacement string.

"." - This matches any single character

"\1" - The first (and only) pattern saved above

"XX" - Your special chars
Bob E Campbell
Honored Contributor

Re: Place 2 digit letter in a file at particular place

OK, several examples in case you asked the wrong question.

By position:

# sed -e "1 s/\(.\{35\}\)/\145/" < temp
00XXXXXXXXXX20081110XXXXXXXXXX00TT145

By TT1:

# sed -e "1 s/TT1/TT145/" < temp
00XXXXXXXXXX20081110XXXXXXXXXX00TT145

By end of line:

# sed -e "1 s/$/45/" < temp
00XXXXXXXXXX20081110XXXXXXXXXX00TT145
PK_1975
Frequent Advisor

Re: Place 2 digit letter in a file at particular place

Its working

Thanks You so much
PK_1975
Frequent Advisor

Re: Place 2 digit letter in a file at particular place

Hello

In this reponses I did not see any drop down box to assign Point "unassigned" look like, I have assigned some of the response, could you tell me how to assign
Bob E Campbell
Honored Contributor

Re: Place 2 digit letter in a file at particular place

Only the original account (pk1974) can assign points. That said, don't kill yourself on my account ;-)