I’ve a file with 2 lines having key, value pair on each line. “//” is used as comment style.
1. key = "string_key_value" //string key
How can I extract string_key_value without quotes?
2. key =100 //integer value
How can I extract 100 from here as an integer?
I’ve to re-use these values in another unix command.
Try this:
It pulls out everything after
key =and before a closing quote/space/semicolon. if you’ve got strings with escaped quotes, this will fail, so this should only be used if you need a quick and dirty solution. If you are parsing production data, log files etc, you should use a module in theParse::family on CPAN, rather than using regular expressions.Perhaps you should be defining these values in a central location (like a constants file, or a config file), rather than attempting to parse source code.. it would be far less error-prone (not to mention hacky).