![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to write the file by position | ford2020 | Shell Programming and Scripting | 1 | 05-03-2009 12:42 AM |
| find if a position is between a given start and end position | fadista | UNIX for Dummies Questions & Answers | 9 | 12-04-2008 12:17 PM |
| how to find a position and print some string in the next and same position | naveenkcl | Shell Programming and Scripting | 1 | 08-21-2008 01:18 PM |
| How to get the position of a file | ravi214u | Shell Programming and Scripting | 3 | 07-07-2008 11:10 AM |
| Read value from particular position in file. | krishnarao | Shell Programming and Scripting | 2 | 05-15-2008 06:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Replacing a position in a file
Hi
I'm trying to use awk in a file(test123.dat). My requirement is to to check for the 65th position, if the 65th position is a space then replace the 65th position by the number 9. This is the code that i used: awk '{substr($0,65,1) ~ / / }{sub(substr($0,65,1),"9")}{print}' test123.dat But this doesnt work ![]() Plz Help... |
|
||||
|
A little change...
Code:
awk '{if(substr($0,65,1)==" ")sub(substr($0,65,1),"9");print}'
by the way this was wrong Code:
(substr($0,5,1) ~ / / ) by the way this was wrong Code:
(substr($0,5,1) ~ / / ) |
|
||||
|
This is a sample data from the file test123.dat
0049DA06152009FPA06USD 000000000000D000000000009.9 If i use awk '{if(substr($0,65,1)==" ")sub(substr($0,65,1),"9");print}' test123.dat this is the result that i get, the "9" gets appended after USD 0049DA06152009FPA06USD9 000000000000D000000000009.9 but i should get the result 0049DA06152009FPA06USD 000000000000D000000000009.99 |
|
||||
|
I had pasted only a part of the data in my previous post, sorry abt it
This is the actual data in the file 0049DA06152009FPA06USD 000000000000D000000000009.9 ORA100144 The total length is 149 and im trying to do the changes in the 65th position When i post the actual data the spaces/tabs in the actual data does not get posted. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|