Hi,
In a KSH script I have following code, which checks inside a file for the word "Report:" and extracts the report id which follows this tag:
reportid=`grep -i "Report:" ${in_file} | sed -e 's/.*Report:[ ]*\([A-Za-z0-9]*\).*/\1/g;;q'`
The search is repeated for various other literal "tags".
I would like to use variables instead of the literals "Report:" etc, so that the literal is not repeated and the code will be more maintanable and elegant:
tag1="Report:"
tag2= ...
reportid=`grep -i "${tag1}" ${in_file} | sed -e 's/.*"${tag1}"[ ]*\([A-Za-z0-9]*\).*/\1/g;;q'`
My problem is that while grep works ok with the variable, as long as it is enclodes by quotes as above, sed no longer worked. I have tried various ways with or without quotes, escaping the dollar sign, etc.
Any suggestions? Thanks!
In a KSH script I have following code, which checks inside a file for the word "Report:" and extracts the report id which follows this tag:
reportid=`grep -i "Report:" ${in_file} | sed -e 's/.*Report:[ ]*\([A-Za-z0-9]*\).*/\1/g;;q'`
The search is repeated for various other literal "tags".
I would like to use variables instead of the literals "Report:" etc, so that the literal is not repeated and the code will be more maintanable and elegant:
tag1="Report:"
tag2= ...
reportid=`grep -i "${tag1}" ${in_file} | sed -e 's/.*"${tag1}"[ ]*\([A-Za-z0-9]*\).*/\1/g;;q'`
My problem is that while grep works ok with the variable, as long as it is enclodes by quotes as above, sed no longer worked. I have tried various ways with or without quotes, escaping the dollar sign, etc.
Any suggestions? Thanks!