I've got a semicolon delimited file. I would like to search for fields that match a pattern, and not hardcoded eg "mth".
*th=something
If the delimited field fulfills this condition, eg. mth=value
I would like to print out both key and value for some number comparison.
eg. if value > "12" print "invalid mth"
if value > "0" && < 13 print "valid mth"
Is it possible to do this without reading the file by byte?
File that I have
LOG
1997;Ford;E350;"ac;abs;moon";3000.00;
1999;Chevy;"Venture"";mth=/07;
xtendedEdition""";"";4900.00;
1999;Chevy;"Venture""ExtendedEdition;VeryLarge""";"";5000.00;
1996;Jeep;GrandCherokee;"MUSTSELL!;
air;month=08;loaded";4799.00;
1997;Ford;E350;"ac;abs;moon";3000.00;1999;Chevy;"Venture""Exte
ndedEdition""";"";4900.001999;Chevy;"Venture""ExtendedEditi
on;VeryLarge""";"";5000.00
1996;Jeep;mth=Aug/2010;"MUSTSELL!
air;moonroof;loaded";4799.00
Output that I'm interested in
mth=/07
month=08
mth=Aug/2010
Thank you.
Try this:
awk -F\; '{for(i=1;i<=NF;i++) {if($i ~ /m*th/){print $i}}}' file
Thank you for your prompt reply.
I wish to perform some additional functions in your current command. I would like to get the key and value pair.
FS="="
split($i, MTH)
key = MTH[1]
value = MTH[2]
FS="/" # if there is no / separator, can I just check the value?
split($value, MTHCHECK)
oldmth=value[1]
newmth=value[2]
# if the value is null -z just skip the check
if oldmth > "12" print "invalid mth"
if oldmth > "0" && < "13" print "valid mth"
if newmth> "12" print "invalid mth"
if newmth > "0" && < "13" print "valid mth"
How do i incorporate all this into an awk command? I am using bash by the way. Thanks again.
alienated:
Thank you for your prompt reply.
I wish to perform some additional functions in your current command. I would like to get the key and value pair.
FS="="
split($i, MTH)
key = MTH[1]
value = MTH[2]
FS="/" # if there is no / separator, can I just check the value?
split($value, MTHCHECK)
oldmth=value[1]
newmth=value[2]
# if the value is null -z just skip the check
if oldmth > "12" print "invalid mth"
if oldmth > "0" && < "13" print "valid mth"
if newmth> "12" print "invalid mth"
if newmth > "0" && < "13" print "valid mth"
How do i incorporate all this into an awk command? I am using bash by the way. Thanks again.
The awk command gives the output as you desire in your first post.
Can you post the exact desired output from the given log file?
milo7
August 5, 2010, 12:01pm
5
Basically, I expected 5 kinds of output after the = sign.
# '/' slash is the delimiter
month=; #No Month Value
month=/; #No Month Value
month=01/02; #Valid Month/Valid Month
month=/02; #No Month Value/Valid Month
month=13/; #Invalid Month/No Month Value
given the file in my first post, and the validation logic in my second post, i would like to print
#original value followed by validation results
mth=/07 No Month Value/Valid Month
month=08 Valid Month
mth=Aug/2010 Invalid Month/Invalid Month
I hope you can understand what I am trying to put across
Why do you use another username?
Much more I'm afraid..
Maybe it's easier to pipe the output of the first awk command to another awk command, play around with something like:
awk -F\; '{for(i=1;i<=NF;i++) {if($i ~ /m*th/){print $i}}}' file |
awk -F"[/=]" '{
if($2=="" && $3==""){print $0, " #No Month Value/ #No Month Value";next}
if($2=="" && $3==""){print $0, " #No Month Value/ #No Month Value";next}
if(int($2)!= $2 && $3==""){print $0, " #Invalid Month / #No Month Value";next}
.
.
.
'