![]() |
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 |
| insert multiple lines into a file | c0mrade | Shell Programming and Scripting | 12 | 09-04-2008 04:04 PM |
| Insert 2 lines in a file at a specific location | potro | Shell Programming and Scripting | 2 | 05-08-2008 07:38 PM |
| Remove duplicates from File from specific location | gopikgunda | Shell Programming and Scripting | 1 | 04-09-2008 02:16 AM |
| insert file 1 at a specific place of file 2 | JCR | Shell Programming and Scripting | 1 | 02-01-2007 11:48 AM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-23-2005 12:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Insert lines at specific location in file
Hi There
I have this file that I would like to add entries to, however, there is a "}" as the last line that I need to keep. Basically i would like to know how I can write a script that will add new lines at the second to last line position (ie always add new line above the close bracket) Now, I know how to do this by grep'ing tailing, appending etc using temporary files to put stuff in, but I wanted to do it in one simple command rather than 5 or 6 commands with other temp files involved that I have to remove afterwards (it looks very messy) Is there any way to do this simply ???? Code:
stuff stuff stuff <NEED TO ENTER LINE HERE> } |
|
||||
|
Try this...
Code:
sed '$ i this is line you want to add' filename u142115@linux2alm:~/aps/aps4/product/den> cat sc.txt stuff stuff stuff } u142115@linux2alm:~/aps/aps4/product/den> sed '$ i this is the line' sc.txt stuff stuff stuff this is the line } |
|
||||
|
Quote:
when I run this I get Code:
[my.server] # sed '$ i this is the line' testfile sed: command garbled: $ i this is the line [my.server] # |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|