![]() |
|
|
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 03: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 01: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 |
| how to insert and delete characters in the middle of file | ivancheung | High Level Programming | 7 | 10-11-2004 04:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Inserting text into a file either through standard UNIX commands such as sed(1) or awk(1) or through use of a customized program will require, at least, a temporary file. An example of the former would be:
FILE=filename sed -e "s/this text/for that/" 1>/tmp/$FILE.tmp && cat /tmp/$FILE.tmp > $FILE && rm /tmp/$FILE.tmp A C example is a bit more complex (and will not be attempted without additional specifications) but would roughly work as: 1 ) Open current file 2 ) Open temporary file from tmpnam(3C) 3 ) Read current file making changes as necessary and write to temporary 4 ) Rewind both files 5 ) Read temporary file writing to current file 6 ) Resize/truncate current file (Necessary if temporary file is smaller than original, not required otherwise; good practice to always do anyway) 7 ) Close both files I hope this is helpful. |
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|