Hi,
I want to find the records using grep with following conditions.
one field position at 26 and having length 2 and values of 21,24,31,34 or
another field position at 28 and length 2 of values 21,224,31,34
I wrote it like below, But I want this search using grep, can any one provide?
awk 'substr($0,26,2)==21 || substr($0,26,2)==24 || substr($0,26,2)==31 || substr($0,26,2)==34 || substr($0,28,2)==21 ||substr($0,28,2)==24||substr($0,28,2)==31 ||substr($0,28,2)==24{print $0}' R3AP200811_GMSSMSTRLD_01358_20081119235959.traf_load
Regards,
Venkat
i'm not sure to understand why you say toy use grep, if i understandign you i think you need cut:
while read line
do
var=`echo $line |cut -c26,27 `
var2=`echo $line|cut -c28,29 `
if [ $var -eq $NUMBER1 -o $ var2 -eq $NUMBER1 ..................................... ]
then
...............
else
...............
fi
done< file
grep -E '^.{25}(21|24|31|34)(21|24|31|34)' file
This way you ignore OR. With your code both fileds (26-27) AND (28-29) have to be true. If I understud it good, it�s enought that one condition is satisfied.
grep -E "^.{25}((21|24|31|34)..|..(21|24|31|34))" file
Or, a shorter version that takes advantage of the cross product:
grep -E "^.{25}([23][14]..|..[23][14])" file
tyler_durden