![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read value from particular position in file. | krishnarao | Shell Programming and Scripting | 2 | 05-15-2008 03:49 AM |
| How to check a word position in a file ? | tibo | Shell Programming and Scripting | 7 | 01-03-2008 10:20 PM |
| Sorting a flat file based on multiple colums(using character position) | cucubird | Shell Programming and Scripting | 8 | 07-24-2006 09:47 PM |
| find the position in a file and insert the data there | isingh786 | HP-UX | 5 | 04-11-2006 06:31 PM |
| How to insert strings at certain position | whatisthis | Shell Programming and Scripting | 14 | 11-14-2005 02:40 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
How to insert at a particular position in flat file
Hi All,
I have a flat file with ~ as de-limiter (e.g: aaa~ba a~caa~0~d~e) What I want is check if the 4th character is 0 and replace it with say 4. So now it becomes : aaa~ba a~caa~4~d~e. I have to do this for the whole file, but the delimiter position remains the same, not the character length. Please help. Abhi. |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
awk -F'~' 'BEGIN{OFS="~";}{ if ($4 != 4){$4=4;} print }' your_file
Code:
awk -F'~' 'BEGIN{OFS="~";}{ if ($4 == 0){$4=4;} print }' your_file
Last edited by lorcan; 08-07-2007 at 02:06 AM. Reason: Changing as per req |