Sorry, I have not tried to be theoretical.
There is no codetags.
I just want to search this file find the .SQL scripts and compare them to a file that i have.
There are two other sql script names in this file and i can find them easily but this one has no space before it, in reality when my job is running i would not know the variable name or the script name etc
This is a snipit of code from my input file.
All the following code is on one line.
...EXIT 16 FI JOBNAME=DA331Z_LD_CCC_BSE_TBLS_M PROCNAME1=VEH_INC_PART_UPDTBASE_M.SQL $ORACLE_SCRIPT_PROC/SQLSCRIPT_BATCH INC_PART2_UPDTBASE_M.SQL
SCRERROR=$? IF [ $SCRERROR -NE 0 ] THEN ECHO "ERROR: " INC_PART2_UPDTBASE_M.SQL" FAILED ...
What this means is do a Windows highlight of the code or data in your post then click on the "Wrap [CODE] tags around selected item" toolbar button.
Hover the mouse over the various icons on the toolbar to find the right toolbar icon. On my screen the correct toolbar item appears to be greyed out ... but it works once you can find it. The faint icon looks like a finger pointing at the word "CODE" but at 1024/768 screen resolution you need a magnifying glass and a big torch to read it.
Once posted in "Code Tags" other posters can cut/paste your code or data without corruption or unwanted formatting (like loss of spacing).
When your post is about subtle processing issues with different spacing in the data, posting samples with and without the problem is important.
Precision is everything in computing. Exactly how long is "very long"?
Sorry to be blunt, but in SQL programming terms this is total gibberish. It looks like a mixture of unix script and bits of SQL with additional "..." strings.
We don't mind if you post some practice posts, but please post the entire unix script in "Code Tags", blanking anything confidential with X's.
If you can cut/paste the code from your post and it is identical, we can do the same.
... and while I am on my high horse, the correct spelling is "snippet". LOL
I'm not totally sure what you want to do in the end, so maybe I'm way off here. If so, sorry.
Given your snippet,
Assume that is in a file called "bla.txt".
This:
Will output:
PROCNAME1 VEH_INC_PART_UPDTBASE_M.SQL
If you had more scripts in it it would pick up each one (I think), unless the var/proc pair was broken up by a carriage return.
You can probably tune it quite a bit for your situation, whatever that is.
Brief explanation:
-i case insensitive match
-o just print the matched string, not the whole line like usual
-P use Perl regex's (for the lookbehind)
(<?<= ) lookbehind matches the space before your "proc" name but keeps it out of the -o print
[[:alnum:]_]+=[[:alnum:]_]+\.SQL match one or more alphanumeric or _ characters followed by "=" followed by one or more alphanumerics or _ followed by ".sql"
Then pipe it to awk to print the first and second fields delimited by "=".
You could do other things too like add a -r to the grep to search a whole directory structure recursively, or pipe everything to "sort -u" to eliminate duplicate results, even "sort | uniq -c | sort -n" to get numeric values for how often the same proc/var name pairs occur.
---------- Post updated Jan 20th, 2011 at 03:58 PM ---------- Previous update was Jan 19th, 2011 at 10:58 PM ----------
I just realized I should have posted that reply to owenian rather than methyl to be in the proper place in this thread....sorry...it's my first post @ unix.com.
If you describe what "can't get it to work" means I might be able to help. I could imagine maybe your version of grep is different, e.g. maybe doesn't support the -P option.
hm, well you could just download (& build & install) gnu grep, which does have the -o and -P switches:http: / / directory.fsf.org / project / grep /
(remove the spaces)
Otherwise, this sort of works but is quite ugly:
Getting a fuller-featured version of grep would be much cleaner.