Sponsored Content
Top Forums Shell Programming and Scripting Awk command to replace specific position characters. Post 302594630 by pinnacle on Tuesday 31st of January 2012 09:22:06 PM
Old 01-31-2012
Thanks Chubler_XL. This works.
Sir could you please explain what we are doing in this.
I understand that we defined a function called "repl" which takes four parameters.
And then calling it 3 times.
I dont understand the following:
Quote:

sprintf("%-*s", t-f+1, v) substr(s,t+1) ---> What does this part does

we are storing all the return values in "a" and printing it. So will the values not get overwritten.
a=repl($0,96,98,"ABC")
a=repl(a,99,113,"DEF")
a=repl(a,190,198,"XYZ")
print a
And also when we are replacing characters from 99 to 113 with "DEF" without trailing spaces. How does it not mess the format.

Would really appreciate if you could explain this to me.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

2. Shell Programming and Scripting

Using sed to replace specific character and specific position

I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done? Example: File: A0199999123 A0199999124 A0199999125 Need to replace 99999 in positions 3-7 with 88888. Any help is appreciated. (5 Replies)
Discussion started by: programmer22
5 Replies

3. Shell Programming and Scripting

Add characters at specific position in file

Hello I want to add some value at the specific position. My file has data like Hello Welcome to UNIX Forums Need Assistance I want to add some value at the end but at same character position for all lines. I want my output file to have data like : Here '_' represents blanks.... (3 Replies)
Discussion started by: dashing201
3 Replies

4. Shell Programming and Scripting

Sed position specific replace

I'm drawing a blank on how to use sed to replace selectively based on position in the string (vs nth occurence): hello.|there.|how.|are.|you.| I want the period removed in the 3rd item (as defined by the pipe delimiter) if a period is present. So the result in this case would be: ... (2 Replies)
Discussion started by: tiggyboo
2 Replies

5. Shell Programming and Scripting

Using sed to replace a string in a specific position

I asked this before, but my problem got more complicated. Heres what I am trying to do: I'm trying to replace a string at a certain location with another string. Heres the file I'm trying to change: \E I want to replace the escape code at the 3rd line, 2nd column with this escape code... (3 Replies)
Discussion started by: tinman47
3 Replies

6. Shell Programming and Scripting

position specific replace in file

How to replace the position specific values in the file.. i searched a lot the forums but i couldn't able to do... i have file like below 576666666666666666666666666 7878 897987 121 0asdas Y12 5900fbb 777 09JJJ 78798347892374 234234234364 234232898 89HJHIHIGIUG989902743748327khjkhkjlh... (6 Replies)
Discussion started by: greenworld123
6 Replies

7. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

8. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

9. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies

10. Shell Programming and Scripting

sed command on AIX, replace specific characters

Hi, Im using sed on an AIX machine. I am trying to change the 137-139 characters if they are a ' 36'/'000' to a '036'. The positions that need to be changed are fixed. the source data that I have is$cat v.txt 4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY... (9 Replies)
Discussion started by: dsid
9 Replies
MH-MAIL(5)							     [nmh-1.5]								MH-MAIL(5)

NAME
mh-mail - message format for nmh message system SYNOPSIS
any nmh command DESCRIPTION
nmh processes messages in a particular format. It should be noted that although neither Bell nor Berkeley mailers produce message files in the format that nmh prefers, nmh can read message files in that antiquated format. Each user possesses a mail drop box which initially receives all messages processed by post. Inc will read from that drop box and incorpo- rate the new messages found there into the user's own mail folders (typically "+inbox"). The mail drop box consists of one or more mes- sages. Messages are expected to consist of lines of text. Graphics and binary data are not handled. No data compression is accepted. All text is clear ASCII 7-bit data. The general "memo" framework of RFC-822 is used. A message consists of a block of information in a rigid format, followed by general text with no specified format. The rigidly formatted first part of a message is called the header, and the free-format portion is called the body. The header must always exist, but the body is optional. These parts are separated by an empty line, i.e., two consecutive newline characters. Within nmh , the header and body may be separated by a line consisting of dashes: From: Local Mailbox <user@example.com> To: cc: Fcc: +outbox Subject: The header is composed of one or more header items. Each header item can be viewed as a single logical line of ASCII characters. If the text of a header item extends across several real lines, the continuation lines are indicated by leading spaces or tabs. Each header item is called a component and is composed of a keyword or name, along with associated text. The keyword begins at the left margin, may NOT contain spaces or tabs, may not exceed 63 characters (as specified by RFC-822), and is terminated by a colon (`:'). Cer- tain components (as identified by their keywords) must follow rigidly defined formats in their text portions. The text for most formatted components (e.g., "Date:" and "Message-Id:") is produced automatically. The only ones entered by the user are address fields such as "To:", "cc:", etc. Internet addresses are assigned mailbox names and host computer specifications. The rough for- mat is "local@domain", such as "MH@UCI", or "MH@UCI-ICSA.ARPA". Multiple addresses are separated by commas. A missing host/domain is assumed to be the local host/domain. As mentioned above, a blank line (or a line of dashes) signals that all following text up to the end of the file is the body. No format- ting is expected or enforced within the body. Following is a list of header components that are considered meaningful to various nmh programs. Date: Added by post, contains date and time of the message's entry into the mail transport system. From: This header is filled in by default with the system's idea of the user's local mailbox. This can be changed with the Local-Mailbox profile entry. It contains the address of the author or authors (may be more than one if a "Sender:" field is present). For a stan- dard reply (using repl), the reply address is constructed by checking the following headers (in this order): "Mail-Reply-To:", "Reply-To:", "From:", "Sender:". A "From:" header MUST exist when the message is sent to post, otherwise the message will be rejected. Mail-Reply-To: For a standard reply (using repl), the reply address is constructed by checking the following headers (in this order): "Mail- Reply-To:", "Reply-To:", "From:", "Sender:". Mail-Followup-To: When making a "group" reply (using repl -group), any addresses in this field will take precedence, and no other reply address will be added to the draft. If this header is not available, then the return addresses will be constructed from the "Mail-Reply-To:", or "Reply-To:", or "From:", along with adding the addresses from the headers "To:", "cc:", as well as adding your personal address. Reply-To: For a standard reply (using repl), the reply address is constructed by checking the following headers (in this order): "Mail- Reply-To:", "Reply-To:", "From:", "Sender:". Sender: Required by post in the event that the message has multiple addresses on the "From:" line. It is otherwise optional. This line should contain the address of the actual sender. To: Contains addresses of primary recipients. cc: Contains addresses of secondary recipients. Bcc: Still more recipients. However, the "Bcc:" line is not copied onto the message as delivered, so these recipients are not listed. nmh uses an encapsulation method for blind copies, see send(1). Dcc: Still more recipients. However, the "Dcc:" line is not copied onto the messages as delivered. Recipients on the "Dcc:" line receive the same messsage as recipients on the "To:" and "cc:" lines. See send(1) for more details. Fcc: Causes post to copy the message into the specified folder for the sender, if the message was successfully given to the transport sys- tem. Message-ID: A unique message identifier added by post if the -msgid flag is set. Subject: Sender's commentary. It is displayed by scan. In-Reply-To: A commentary line added by repl when replying to a message. Resent-Date: Added when redistributing a message by post. Resent-From: Added when redistributing a message by post. Resent-To: New recipients for a message resent by dist. Resent-cc: Still more recipients. See "cc:" and "Resent-To:". Resent-Bcc: Even more recipients. See "Bcc:" and "Resent-To:". Resent-Fcc: Copy resent message into a folder. See "Fcc:" and "Resent-To:". Resent-Message-Id: A unique identifier glued on by post if the -msgid flag is set. See "Message-Id:" and "Resent-To:". Resent: Annotation for dist under the -annotate option. Forwarded: Annotation for forw under the -annotate option. Replied: Annotation for repl under the -annotate option. FILES
/var/mail/$USER Location of mail drop SEE ALSO
Standard for the Format of ARPA Internet Text Messages (RFC-822) CONTEXT
None MH.6.8 11 June 2012 MH-MAIL(5)
All times are GMT -4. The time now is 04:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy