The UNIX and Linux Forums  


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



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
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 04:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 11:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 08:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 04:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-05-2006
clauchiorean clauchiorean is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 3
Sed script

/\/\*/!b
:x
/\*\//!{
N
bx
}
s/\/\*.*\*\///

This scipt should remove c like commnets /**/

i know what de last line does
but i dont't know what the first lines do
Can anyone explain please
  #2 (permalink)  
Old 04-05-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
If the comment spans for more than one line, then it will append all lines together to make it as a single line...

for example, if your program contains comment like

/** this is fist line
extended to next line
closed here **/

then the first section of sed script will convert it as single line

/** this is fist line extended to next line closed here **/

Then the last section of sed script will delete the anything in between /* and */


Here is how it works :
======================

example :

$more mah.txt
a
b
/*** this is a comment
extented to next line
and ends here ***/
c
d /** this is also comment **/
e
f
g
h


first line of sed script is "/\/\*/!b" - check for "/*" pattern in the line, if not found branch to the end of sed script, ie. don't do anything to the current line of input file and proceed to next line of input file... b denotes branch, hence there is no lable next to b, it will branch/go to the end of sed script

1st and 2nd line of input file (mah.txt) do not contain "/*", hence it won't do anything for the first two lines

now, the third line of input file contains "/*" ( "/*** this is a comment" ).. hence first line of the sed script fails, then go the next line in sed script and creates a lable :x ( you will use it later )...
next search for "*/" in the current line, if not found then append ( N in sed ) next line of the input file to current line ...
now 3rd and 4th line got appended as single line and now the current line contains "/*** this is a comment
extented to next line"
then branch/go to the lable x (ie bx in sed ).. it goes back to line :x in sed script

next line in the sed script again checks for "*/", if not found then append the next line again ( N in sed ), now along with 3rd and 4th line of input file, 5 line also will get appended... now the current line holds "/*** this is a commentextented to next lineand ends here ***/"
Next line in the sed script says brach/go back to lable x. Now again we are back to the lable :x, the next line sed script searchs for "*/", this time it matches and proceeds... and do a s/\/\*.*\*\/// which will delete the comment fully.


There is a good article on the net which explains in detail about the hold spaces, pattern spaces, branching etc..

http://www.grymoire.com/Unix/Sed.html
  #3 (permalink)  
Old 04-06-2006
clauchiorean clauchiorean is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 3
is there a way to make this script replece te lines with empty lines
not just erase them

say the lines between comments
1: blabal /* bbbb
2: cccc
3: aaaaa
4: */ bla


want to erase this but i want also to preseve de lines as empty lines

something like this

1: blabal
2:
3:
4: bla

because I want to prezerve de actual nr of lines

or can i obtain somehow the line nrs

Last edited by clauchiorean; 04-06-2006 at 10:52 AM..
  #4 (permalink)  
Old 04-14-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
sorry.. i'm not getting emails for the posts.. so i didn't check it

let me check

Last edited by mahendramahendr; 04-14-2006 at 07:51 PM..
Closed Thread

Bookmarks

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 On




All times are GMT -4. The time now is 03:54 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0