sed command on AIX, replace specific characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command on AIX, replace specific characters
# 8  
Old 03-31-2017
Quote:
Originally Posted by MadeInGermany
I missed something: \1 is certainly a backreference to the ( ) and should become $1 in perl, and needs to be separated from the following text
Code:
perl -i.Original -pe '/^4000/ and s/(.{136}) 36|000/${1}036/' file

saved me thereSmilieSmilie
# 9  
Old 03-31-2017
Quote:
Originally Posted by MadeInGermany
I missed something: \1 is certainly a backreference to the ( ) and should become $1 in perl, and needs to be separated from the following text
Code:
perl -i.Original -pe '/^4000/ and s/(.{136}) 36|000/${1}036/' file

AFAIK in perl both $1 and \1 can be used for backreference:

Quote:
Absolute numbered groups were referred to using \1 , \2 , etc., and this notation is still accepted (and likely always will be). But it leads to some ambiguities if there are more than 9 capture groups, as \10 could mean either the tenth capture group, or the character whose ordinal in octal is 010 (a backspace in ASCII). Perl resolves this ambiguity by interpreting \10 as a backreference only if at least 10 left parentheses have opened before it. Likewise \11 is a backreference only if at least 11 left parentheses have opened before it. And so on. \1 through \9 are always interpreted as backreferences.
perlre - perldoc.perl.org
# 10  
Old 04-03-2017
@scrutinizer thanks for tip Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Language Specific Characters in File

Hi Team, I have requirement to replace Language Specific Characters in File. We have set of characters, it should be replaced to a different character in the file. I have around 38 characters which should replaced to different destination character. Please help. Thanks Bharat (3 Replies)
Discussion started by: bharath561989
3 Replies

2. UNIX for Dummies Questions & Answers

How to replace and remove few junk characters from a specific field?

I would like to remove all characters starting with "%" and ending with ")" in the 4th field - please help!! 1412007819.864 /device/services/heartbeatxx 204 0.547%!i(int=0) 0.434 0.112 1412007819.866 /device/services/heartbeatxx 204 0.547%!i(int=1) 0.423 0.123... (10 Replies)
Discussion started by: snemuk14
10 Replies

3. 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

4. Shell Programming and Scripting

Replace specific characters until pattern

Hi experts, My file looks something like this. abcXX4,7,234 abc,defg,45XX23,74,123 The number of commas left of the XX can vary. The question is how can I replace all the commas left of the 'XX' with an underscore? abcXX4,7,234 abc_defg_45XX23,74,123 Thanks! (5 Replies)
Discussion started by: abercrom
5 Replies

5. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

6. Shell Programming and Scripting

Awk command to replace specific position characters.

Hi, I have a fixed width file. The way this file works is say for example there are 30 columns in it each with different sizes say 10,5,2, etc... If data in a field is less than the field size the rest of it is loaded with spaces. I would like an awk command to that would replace I have... (8 Replies)
Discussion started by: pinnacle
8 Replies

7. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

8. Shell Programming and Scripting

Find and replace a string a specific value in specific location in AIX

Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . . (5 Replies)
Discussion started by: techmoris
5 Replies

9. 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

10. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies
Login or Register to Ask a Question