Hello, All.
please help me with this problem.
i need to use variable as regular expression.
some thing like this:
BEGIN {
RS="\n";
ORS="\n";
reg_exp = ".+Dec.+";
# i mean that regular expression is any symbol before "Dec" and any symbol after it. For example <Worksheet ss:Name="December">
}
$0 ~ reg_exp {
print $0
next
}
and i get: error empty regular expression.
if i try like this
$0 ~ /.+Dec.+/{
print $0
next
}
everything is all right.
thanks in advance
but actually a get a reg_exp during running the script
like this
$0 ~ /.+<Worksheet ss:Name.+/{
reg_exp = substr($0,22,3)
# i can print reg_exp. the value of reg_exp is "Dec"
print $0
next
}
and then i use this reg_exp.
the string which hold "<Worksheet ss:Name" is before string which i compare with reg_exp
since you have .+ both infront of the "<Worksheet ss:Name" and behind it, it is also equivalent to /<Worksheet ss:Name/, there is no need to use .+ . However, for completeness, you should show a sample of your data file, and describe how you want your output to be.
Hello, All.
i had problem with connection yesterday and could not unswer.
Thanks a lot.
i've already solved my problem.
my problem was:
i was trying to use reg_exp before i assign this variable.
my script was:
BEGIN {
RS="\n";
ORS="\n";
reg_exp="";
}
$0 ~ /.+<Worksheet ss:Name.+/{
reg_exp = substr($0,22,3)
print $0
next
}
$0 ~ reg_exp {
print $0
print "TEST"
next
}