Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-11-2003
Registered User
 

Join Date: Apr 2002
Posts: 20
Question sed/awk to insert comment at defined line number

Hi there,

may someone easily help me on this :

I want to insert a text in a specific line number like :

linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1`

line2insert=`expr $linenumb2start + 2`

and now I need to replace something like {} with {comment} at $line2insert.

The line actually is :
.appdata {}
and no identifier can be added to use it for search and substitution. Of course, appdata and {} are already used as well in several locations. Therefore, I really need to use the line number.

Do you have a solution using sed or awk ?

Thanks,
homefp
Sponsored Links
  #2 (permalink)  
Old 03-11-2003
RTM's Avatar
RTM RTM is offline Forum Advisor  
Registered User
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,061
I believe if you read this post you will have the answer you need.
  #3 (permalink)  
Old 03-11-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
Actually, sed can locate a string and then go down 2 lines and then make a substitution all by itself....

sed '/label/{n;n;s/{}/{some comment}/;}'
  #4 (permalink)  
Old 03-14-2003
Registered User
 

Join Date: Apr 2002
Posts: 20
Thanks a lot !!!
This works perfectly as expected.

Is there as well such a single sed command to remove several lines starting from my "label" line after all ?
May be something like : sed '/label/{d.....n;d...}' < filein > fileout ; mv fileout filein

Thanks again,
homefp
  #5 (permalink)  
Old 03-14-2003
Registered User
 

Join Date: Apr 2002
Posts: 20
In fact one line command only to replace sequential sed commands as :

sed '/labe/{n;n;d;}' < filein > fileout; mv fileout filein
sed '/label/{n;d;}' < filein > fileout; mv fileout filein
sed '/label/d' < filein > fileout; mv fileout filein

thanks,
homefp
  #6 (permalink)  
Old 03-14-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
I may be getting a little lost here. What you really want is to delete some lines?? Not insert some text??

If my current understanding of your request is correct, this should do it...
sed '/label/{N;N;d;}' < input > output
  #7 (permalink)  
Old 03-17-2003
Registered User
 

Join Date: Apr 2002
Posts: 20
this was just to finalize my need...
I was wondering if in a single sed command it would be possible to remove several lines starting from my label :
the following :
sed '/label/{N;N;d;}' < input > output
is only removing the second line after label, isn't it ?
But if I want to remove in one shot several lines, having only my label as reference, how should I write my sed command ?

In fact, I would like to replace the 3 lines described in my previous post :
sed '/labe/{n;n;d;}' < filein > fileout; mv fileout filein
sed '/label/{n;d;}' < filein > fileout; mv fileout filein
sed '/label/d' < filein > fileout; mv fileout filein
with only one.

Thanks,
homefp
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 09:29 AM
remove single-line comment Icy002 Programming 3 04-09-2006 09:30 AM
how to insert a line number on every line mopimp UNIX for Dummies Questions & Answers 3 03-25-2006 01:35 PM
Need to add a comment line in a text file orakhan Shell Programming and Scripting 2 09-22-2005 09:36 PM
sed to have defined positionning on line homefp Shell Programming and Scripting 10 04-29-2002 09:42 AM



All times are GMT -4. The time now is 04:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0