![]() |
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 |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 10:19 AM |
| capturing line from script output and appending to a file | wally_welder | Shell Programming and Scripting | 6 | 08-31-2007 03:03 AM |
| Appending line ending with '}" to new line | aismann | Shell Programming and Scripting | 4 | 08-13-2007 02:09 AM |
| Appending the line number and a seperator to each line of a file ? | pjcwhite | Shell Programming and Scripting | 4 | 03-21-2007 01:29 AM |
| Appending data at the first and last line of a file | brainstormer | Shell Programming and Scripting | 4 | 01-03-2007 10:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Appending a line in a file after a particular line
Hello,
I have got a C file in which I would like to add an include statement of my own. There are already a few include statements and mine should come right after the last existing one (to be neat). With grep I can get the lines containing the word 'include' and I guess I should feed the last line of the result to a sed command to append a line but I don't know exactly how to do this part. Any suggestions ? Thanks a lot in advance Max |
|
||||
|
Yes, this is part of the process of updating many C files which cannot be reasonably made by hand.
by using the following: Code:
sed '/#include/ a\ #include "myHeader.h"' input > ouput Max |
|
||||
|
Quote:
Code:
sed '/^#include/{
n;/^#include/!{i\
#include "myHeader.h"
}
}' input > output
|
|
||||
|
The solution with sed worked fine as well.
Thanks !! Max |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|