![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep in Shell script | Krishnaramjis | Shell Programming and Scripting | 1 | 02-19-2008 06:43 PM |
| grep script | drchris | UNIX for Dummies Questions & Answers | 4 | 05-17-2007 06:32 AM |
| a script to simplify the use of grep | kemobyte | Shell Programming and Scripting | 2 | 05-01-2007 10:57 AM |
| grep from a script... | hamsasal | UNIX for Advanced & Expert Users | 1 | 08-14-2005 01:24 AM |
| script ksh/awk/grep | hoang | Shell Programming and Scripting | 2 | 06-01-2002 12:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Quote:
thank you |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
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: Code:
#!/bin/sh case $# in 1|2) echo "Syntax: $0 string1 string2 files ..." >&2; exit 1;; esac first=$1 shift second=$2 shift grep "\\[$1\\]" "$@" | grep "\\[$2\\]" 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). |
|
#10
|
|||
|
|||
|
Thanks, much appreciated - it gives me a good start and a little more understanding.
|
|
#11
|
|||
|
|||
|
Is there anyway I can do the same for the date - ie user input?
I tried a similar format to the scripts already given but it doesnt work |
|
#12
|
|||
|
|||
|
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.
|
|
#13
|
|||
|
|||
|
Thanks Era - I have managed to implement the user date input.
|
|
#14
|
|||
|
|||
|
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 e.g. 01:59:36 -- sending request [type=8|desc=Execution Report] | [35 ] [8] | [57 ] [***] | [115 ] [***] | [128 ] [***] | [50 ] [***] | [56 ] [***] | [49 ] [***] | [34 ] [3] | [52 ] [20080515-05:59:36] | [15 ] [EUR] | [22 ] [4] | [48 ] [FR0000120404] | [55 ] [FR0000120404] | [38 ] [150] | [32 ] [0] | [75 ] [20080515] | [54 ] [1] | [59 ] [6] | [44 ] [50] | [31 ] [0] | [60 ] [20080515-00:45:55] | [126 ] [20080630-23:00:00] | [39 ] [4] | [20 ] [0] | [37 ] [***] | [14 ] [0] | [6 ] [0] | [17 ] [12108311550651] | [11 ] [055152-A-09MEI08] | [8 ] [FIX.4.0] | [9 ] [0287] | [10 ] [059] |
|||
| Google The UNIX and Linux Forums |