regex or statement with perl one liner
So i have this nasty. long crontab file - here is a sample
Code:
##-------------------------------------- what i want to parse them down to is the relative command names - no path, no log file path, just the command names. the above sample, respectvely - this is what i need. Code:
web_FbEmailF50GovtSunTrd.cmd Code:
cat /tmp/foo | perl -nle 'print /\/(\w+\.[scr|cmd])/' I thought that brackets and a or '|' would say look for a word ending in '.cmd' or a word ending in '.scr' I have tried : Code:
cat /tmp/foo | perl -nle 'print /\/(\w+\.[scr-cmd])/' i want to do something like [cmd|sh|src] - right now the [cmd|src] is picking up both the sh and the src but i then i have to go through the whole crontab to see what they are - are they ending in .sh or .src. and this is a big crontab trust me. my eyes hurt just looking at it. i am going to need to differentiate between the .sh and .src and for that matter those scripts ending in .cmd |
That would be because [] is for a range of characters, hence \.[scr|cmd] says, a period followed by one of s,c,r,|,c,m,d ... which is what was returned
Try using () instead which is a grouping, so \.(scr|cmd) says, a period followed by either scr or cmd |
The () messes up the perl capture.
Code:
crontab -l | perl -nle 'print /\/(\w+\.(scr|cmd))/' |
The following works pretty good on your test data. Comment-out the "next if" line if you want to include commands that are commented out. The "next unless" line is really only useful when you have already commented out the "next if" line. "next unless" is doing a very basic check to see of the line "looks like" a crontab entry, so as to filter out the comment lines (that are no longer being skipped because you took out the "next if"). This "next unless" check fails and gives you one extraneous comment line in the output in the example below. You could make "next unless" a more sophisticated REGEX, or just manually edit out the occassional false hit from the results.
Code:
#!/usr/bin/perl |
How about:
Code:
crontab -l | perl -nle 'print $1 if /\/(\w+\.(scr|cmd))/' |
All times are GMT -5. The time now is 09:25 PM. |