Extract "value=" only from non-comment portion
See the below sed expression which gets value from commented code as well
I tried with grep but that doesn't work also
#!/bin/sh
#set -x
FILE="/tmp/comment.txt"
create_file () {
echo "/*" > $FILE
echo "this is a multi" >> $FILE
echo "line with" >> $FILE
echo "var=20" >> $FILE
echo "and ending the comment */" >> $FILE
echo "var=15" >> $FILE # line after comment
}
create_file
cat $FILE
# This sed should extract only from var=15 which is not part of
# comments, how to do that?
# output should be only 15, instead of "20 and 15"
sed -n "s/\(var=\)\([0-9]*\)/\2/p" $FILE
Actual:
/*
this is a multi
line with
var=20
and ending the comment */
var=15
20
15
Expected:
/*
this is a multi
line with
var=20
and ending the comment */
var=15
15