![]() |
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 insert text in the middle of a file | kartikkumar84@g | UNIX for Dummies Questions & Answers | 6 | 05-10-2008 02:35 PM |
| insert text in the middle of a file | relle | Shell Programming and Scripting | 3 | 03-13-2008 03:37 PM |
| How to insert the 1st arg into the middle of the file | boris | Shell Programming and Scripting | 4 | 04-13-2007 12:21 AM |
| How to insert text into first line of the file and middle of the file? | ali hussain | Shell Programming and Scripting | 3 | 03-05-2007 05:54 AM |
| insert text into the middle of a original file | mopimp | Shell Programming and Scripting | 1 | 03-26-2006 10:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk insert character in the middle of a line
I'm trying to insert a single character at position 11 in everyline of a file.
My input file looks like this: Code:
456781 ~Y~12345
456782 ~N~12300
Code:
45678~1 ~Y~12345
45678~2 ~N~12300
Code:
cat myfile | awk 'print substr($1,1,10) "~" substr($1,11)}' > mynewfile |
|
||||
|
Thanks vino and grasper! It is in position 11, the first 5 characters are spaces so it looks like it's in position 5.
The sed solutions looks a lot more complicated to me. I figured I had to use $0 instead of $1, and yes I was missing the open brace. Thanks guys! Monica |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|