• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

sed and regular expression

I have a 10000 line code file that has the following repeated about 500 times.

/* Present next screen */                                                      
             CHGVAR     VAR(&#VENDN) VALUE('Text1')                            
             CHGVAR     VAR(&#MSG01) VALUE('Text2')                                
             SNDF       RCDFMT(MSGCTL)                                          
             SNDRCVF    RCDFMT(SCRN02)                                          
                                                                               
/* Cancel was selected */                                                      
             IF         COND(&IN12 *EQ '1') THEN(GOTO CMDLBL(@CANMSG))  

I need to delete all occurrences of all the text form the  /* to the ending CMDLBL(@CANMSG)). The text is in VALUE('Text1')  and VALUE('Text2') are never the same.  

I know this can be done with sed but I can't figure out how to get the regex right. I end up selecting the whole file. Thanks for any help you can give with the reqex and sed

0
mhopkins9901
Asked:
mhopkins9901
  • 3
  • 3
  • 2
1 Solution
 
Maciej SsysadminCommented:
You mean from the second "/*"? Is there always "Cancel was selected" text?
0
 
ozoCommented:
sed '/\/\*/,/CMDLBL(@CANMSG))/d'
0
 
mhopkins9901Author Commented:
Yes "Cancel was selected" is always there.

 Do you think it would be less complicated if I did this in two steps.

I guess the "/*" and "*/" makes it a little harder when it shows up twice in the expression.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Maciej SsysadminCommented:
If "Cancel..." is static, you may use something like below:
sed '/\/\* Cancel was selected \*\//,/CMDLBL(@CANMSG))/d' file.txt

Open in new window

0
 
ozoCommented:
Do you want to delete all occurrences of all the text form the  /*
as in /* Present next screen */              
or from the /* Cancel was selected */         ?
0
 
mhopkins9901Author Commented:
Thanks for asking ozo.

I need to delete all occurrences of  all the text in the attached code snippet.
/* Present next screen */                                                       
             CHGVAR     VAR(&#VENDN) VALUE('Text1')                            
             CHGVAR     VAR(&#MSG01) VALUE('Text2')                                 
             SNDF       RCDFMT(MSGCTL)                                          
             SNDRCVF    RCDFMT(SCRN02)                                          
                                                                                
/* Cancel was selected */                                                       
             IF         COND(&IN12 *EQ '1') THEN(GOTO CMDLBL(@CANMSG))   

Open in new window

0
 
ozoCommented:
sed '/\/\*/,/CMDLBL(@CANMSG))/d'
will delete eeverything from the first /* to the CMDLBL(@CANMSG))
0
 
Maciej SsysadminCommented:
So ozo's solution is working one, and you should forget mine one :)
But - it will delete everything from first "/*" up to first CMDLBL(@CANMSG)). Then it will start search "/*" again.
Do you have "/*" somewhere else in your file? If so - be careful, cause you may delete too much.
The best would be to have some sample file, not just text to delete. If you can, attach it here.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now