I'm scripting in ksh and trying to put together a regular expression. I think my logic is sound, but I'm doing the head-against-the-wall routine while trying to put the individual pieces together. Can anybody lend some suggestions to the below problem?
I'm taking a date in the format of "DD-MMM-YY" as a parameter for a script. I want to user-proof this as much as possible, so "01-AUG-13" is valid but nonsense (i.e. "41-MAK-0G") gets rejected. This is a job for regular expressions.
I've broken down the "01-AUG-13" example into five separate expressions to be evaluated, and I think my regex logic is sound. (But if it isn't, please let me know!)
Part 1="01"
Part 2="-"
Part 3="AUG"
Part 4="-"
Part 5="13"
Part 1 translates into:
"match two digits, value between 01 and 31",
Which further translates into:
"match first digit, with value between 0-2, one time, then match second digit value between 0-9 one time |||OR||| match first digit 3 one time (because if we missed the first match of 0-2, then it has to be this and only this), then match second digit, with value of 0 or 1, one time."
Parts 2 & 4 translate into "exactly one dash here"
Part 3 becomes "match exactly one 3 char month name out of the valid set of month name values".
Part 5 is "match exactly two digits".
I have coded the regular expressions for these values as follows:
Part 1:
Parts 2 and 4:
Part 3:
I couldn't think of a simple way to do this without using grep -i; what are some alternatives?
Part 5:
So, all of those pieces seem sound, individually. The function doesn't work once I combine them, however. One of my many iterations (and probably the simplest) is:
I am doing something wrong, but I honestly don't know what it might be. Can anyone lend some suggestions on how I can properly write this regular expression?
Thank you for your assistance. The code you supplied...
...worked perfectly for me!
I guess my problem was a syntax error; I notice you did not enclose the "-" within brackets.
Thank you for pointing out the potential for illogical dates such as 31-FEB. I know my code isn't 100% fool-proof, but I'm writing my script for (reasonably) experienced users, so hopefully I don't have to code against something that foolish.
I like your suggestion to use the date -d. It appears I don't have GNU date available to me, though. That would have been a beautiful solution to the problem, however!
Thank you very much for your assistance! I really appreciate it!
Hello Gurus,
I am looking for regular expressions for awk to filter on second column 2nd and 3rd digit
Using in code something like: awk '{if ( $2 == "0::" ) print}
source file:
0 0:0:0 FC 15 normal 559104 51200 0:3:1* 1:3:1 600
1 0:0:1 FC 15 normal ... (2 Replies)
Hello All,
I'm trying to extract the lines between two consecutive elements of an array from a file.
My array looks like:
problem_arr=(PRS111 PRS213 PRS234)
j=0
while } ]
do
k=`expr $j + 1`
sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt
---some operation goes... (11 Replies)
Hello,
I want to extract text between <td class="di_resultscolumnheader"> and </td>.
I wrote the below code to extract text. But I am able to extract the text for the first match only.
Can some one help me in this?
Thanks in advance.
Code:
if ($line =~ /<td... (5 Replies)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error.
source $CA_VERSION_DATA
if * ]
then
echo "CA_RELESE $CA_RELEASE is invalid"
exit -1
fi
+ source /etc/ncgl/ca_version_data
++ CA_PRODUCT_ID=samxts
++ CA_RELEASE=6
++ CA_WEEK_NO=7
++... (3 Replies)
Hi
I have to extract the first field and the last %field of the following out put..
/home (/abc/def/bhd ) : 522328 total allocated Kb
319448 free allocated Kb
... (2 Replies)
HI All,
I want to list a file with the below format :
testfile_nnnnn.xxxx
where n and x can be any digit 0-9. n repeats 5 times and x 4 times...
I tried with something like below:
ls -l testfile_/\{5\}/*
to start with but its not working. Please could anyone help?
Thanks
D (1 Reply)
Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant.
THX! (2 Replies)