![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 12:31 PM |
| Shell Script: want to insert values in database when update script runs | ring | Shell Programming and Scripting | 1 | 10-25-2007 12:06 AM |
| here document to automate perl script that call script | hogger84 | Shell Programming and Scripting | 3 | 10-22-2007 07:15 AM |
| returning to the parent shell after invoking a script within a script | gurukottur | Shell Programming and Scripting | 5 | 09-26-2006 04:05 AM |
| return valuse from child script to parent script | borncrazy | Shell Programming and Scripting | 1 | 08-20-2004 12:39 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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 06:52 AM. |
|
#4
|
|||
|
|||
|
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 03:51 PM. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|