I am new to this - I have a unix command (below) that I would like to make automated. I would like the script to run the below command line but would like user input for '\[11 \]' and '\[075871-A-28APR08\]' as these values will change depending on what i'm searching for. Is this possible? if so please help.
That is very cool. Thanks! Now how could i debug it to make sure that it is working. For example, i have 2 files in my home directory which is the same place that i am running the script from. For the first value, i put in 2do (i have a file with that name) and also the name of the script for the second value (grepscript.sh). How long should it take it to find those values...in your best guess. I am running a vmware machine on Solaris 10
The script allows you to enter the strings, but not the file to grep in. That was not in the initial requirement.
Also, you would need to fix the spelling of "fist_value" (^:
Passing the strings to grep for on the command line is a little cumbersome, but allows you to improve your searches iteratively if your shell has a history mechanism. Scripts which prompt you are easy for beginners, but you quickly grow out of using them.
If you want to avoid having to type the backslashed square brackets, you can internalize those into the script:
The search time will depend on the number of items in each file (and on the complexity of the search strings, but you are just searching for literal strings which are relatively long, so nothing very complex there). You must know better than any of us how long these things typically take. But chappidi_pradee's script expected the search strings, not file names, as input.
On another note, if you think the backslashes are cumbersome, fgrep will only search for literal strings, so doesn't need backslashes (and indeed, if you put in backslashes, or square brackets, it will search for those characters literally).
The one I pasted above allows you to specify two search strings, and an arbitrary number of input files. It should not be too hard to extend to fill in part of the file name automagically if you want to specify just the date and have the script know to "pad" it with the right directory name and extension etc.
Ok, I can now run this script and choose which parts I want to grep and the date I want to check - I have another question but not sure this can be done.
When I use grep to grep out tag 39 and its value, is there anyway I can get the script to display [11 ] [055152-A-09MEI08] as this is a ref number