|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 . . . . 10Mik0A2M343443 I want to find a value for 2D3M in the 6,7,8,9 positions from the beginning of record, if found need to replace it with 2A3M Thanks |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
sed "s/^\(.\{5\}\)2D3M/\12A3M/" file |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Hi anbu23,
Thanks for quick reply..so this will check for the string only in the 6, 7, 8, 9 positions only right..and it should not check any other positions of every records of the file.. sed "s/^\(.\{5\}\)2D3M/\12A3M/" file what does 1 mean before 2A3M in the above SED command. Pls respond..thanks.. Last edited by techmoris; 03-11-2010 at 05:24 PM.. |
|
#4
|
||||
|
||||
|
sed code will check 2A3M only from 6th to 9th position in the file.
Quote:
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
gr8..thanks/...it worked..)
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Sed is better in this case, here is the awk code. Code:
awk -F "" '{if (substr($0,6,4)=="2D3M") $7="A"}1' OFS="" samp.txt |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to append a string to a specific location in a line | mwrg | Shell Programming and Scripting | 4 | 11-18-2009 02:28 PM |
| Finding a word at specific location in a string | swapnil.nawale | Shell Programming and Scripting | 1 | 09-14-2009 08:49 AM |
| using sed to replace a specific string on a specific line number using variables | todd.cutting | Shell Programming and Scripting | 2 | 08-13-2009 09:40 PM |
| find pid of process run in specific location | JCR | Shell Programming and Scripting | 4 | 07-29-2009 04:25 AM |
| How to replace a specific word in specific column? | ./hari.sh | Shell Programming and Scripting | 6 | 03-07-2009 08:33 AM |
|
|