mhopkins9901
asked on
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
/* 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
You mean from the second "/*"? Is there always "Cancel was selected" text?
sed '/\/\*/,/CMDLBL(@CANMSG))/ d'
ASKER
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.
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.
If "Cancel..." is static, you may use something like below:
sed '/\/\* Cancel was selected \*\//,/CMDLBL(@CANMSG))/d' file.txt
Do you want to delete all occurrences of all the text form the /*
as in /* Present next screen */
or from the /* Cancel was selected */ ?
as in /* Present next screen */
or from the /* Cancel was selected */ ?
ASKER
Thanks for asking ozo.
I need to delete all occurrences of all the text in the attached code snippet.
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))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.