![]() |
|
|
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 |
| Question regarding lm file | mr_deb | UNIX for Dummies Questions & Answers | 5 | 05-22-2008 08:22 AM |
| mk file question | felixmat1 | Shell Programming and Scripting | 2 | 10-11-2007 11:51 PM |
| Post Shell programming: Question about source a file and read data from the file | ccwq | Shell Programming and Scripting | 3 | 08-04-2007 11:28 PM |
| file locking question | Bab00shka | UNIX for Dummies Questions & Answers | 2 | 01-29-2004 10:34 AM |
| Newbie question about difference between executable file and ordinary file | Balaji | UNIX for Dummies Questions & Answers | 1 | 11-29-2000 06:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
I was more curious than anything as to whether there is a way to insert a line of data into a file (at any given line number) without using an editor such as sed.
What I really would like to know is if I can accomplish this without using intermediate files such as noted by the first reply. How can I do this with sed? |
|
||||
|
Unfortunately sed requires the use of temporary files as you can't output to the original file, so either way you're going to have to use temp files.
See this thread for the sed syntax on inserting. Note in the examples 1 is used for the insert, but you can specify the line number as different. |
|
|||||
|
What about using the shell? This will take whatever is in "file1", and place a seperator line before line 5: Code:
#! /bin/ksh
integer n=1
while read line; do
(( n == 5 )) && { print "#------- Seperator ------#"; }
print $line
n=n+1
done < file1
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|