Its working fast for me.. thnks...
But i am not getting the values of these arrays outside the awk ...
[...]
That's why I was asking what is the next task: you can get the values outside,
but I'm sure you can continue with the next task using Awk. Could you describe the next task?
getting the IP and USERAGENT value from the command line argument
call function isInFua ( which is internally calling some othe functions)
FInally i need the Return value (RET_VALUE) like 3G or Smartphone or WAP or WEB...
IP=`echo $ALL_ARGS | awk '{print $1}'` # getting value for IP address
USER_AGENT=$(echo $ALL_ARGS | cut -d'"' -f6) # getting value for USER AGENT
var=0
RET_VALUE=""
function isInFua
{
echo VAR --- $var
isSmartPhone # calling function for Smart phone
if [ $var == 1 ]
then
RET_VALUE=SmartPhone
return
fi
isThreeG # calling function for 3G
if [ $var == 1 ]
then
RET_VALUE=3G
return
fi
isFromWAP # calling function for WAP
if [ $var == 1 ]
then
RET_VALUE=WAP
return
fi
isFromWEB # # calling function for WEB
if [ $var == 1 ]
then
RET_VALUE=WEB
return
fi
}
#------------------------------------------------------------------------------#
# Test 3G and 2.5G on a user-agent functions #
#------------------------------------------------------------------------------#
function isSmartPhone
{
for ((i = 0 ; i < $SIZE_SP_ARRAY ; i++))
do
USER_AGENT_VALUE=`echo $USER_AGENT | grep "${SP_ARRAY[$i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isThreeG
{
for ((i = 0 ; i < $SIZE_THREEG_ARRAY ; i++))
do
USER_AGENT_VALUE=`echo $USER_AGENT | grep "${THREEG_ARRAY[$i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isFromWAP
{
for ((i = 0 ; i < ${#IPMobile[*]} ; i++))
do
IP_MOBILE_VALUE=`echo $IP | grep "${IPMobile[i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isFromWEB
{
for ((i = 0 ; i < ${#IPWeb[*]} ; i++))
do
IP_MOBILE_VALUE=`echo $IP | grep "${IPWeb[i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
isInFua
echo RET_VALUE = $RET_VALUE
Can you please go through with this ??
Thanks for the help...
My script(analyseTrafic.sh) is calling by another script like this
temp="10.48.81.109 - - [18/Jul/2008:15:20:12 +0200] \"GET /cacti/settings.php?tab=general HTTP/1.1\" 200 14457 \"http://10.58.198.153/cacti/settings.php?tab=path\" \"SPV.*E65 Profile/MIDP-2.0 Configuration/CLDC-1.0 UP.Link/6.2.3.15.0\""
./analyseTrafic.sh $temp
The IP Value will be 10.48.81.109 and USER_AGENT is "SPV.*E65 Profile/MIDP-2.0 Configuration/CLDC-1.0 UP.Link/6.2.3.15.0\" inside analyseTrafic.sh
A few suggestions:
I see your're using bash syntax and you're invoking the script as /bin/sh
so I assume you're on Linux and probably you have a recent bash version.
If that's the case, you could use a different approach for the look up:
1. Extract the USER_AGENT from the argument (or the first argument, if you
invoke the script like this: ./analyseTrafic.sh "$temp"):
[assuming GNU grep and recent bash on Linux]
extracting from all arguments:
extracting from the first one:
2. Look it up in the file ("$_pat") with grep:
And then use the [[ ]] bash operator to test for the 3G string at the beginning.
The requirement is i need to find an array value matching with pattern {5:{ , replace that with 5: and reassign that to same array index and print it.
I write something like below and the issue is sed command is not working. If i replace " with "`" the script gives syntax error.how can i... (8 Replies)
Hi guys
Let me at first describe the whole thing that I'm trying to do. Lets say I have 100 files like the following one.
Ow 1230 16.000000 -0.834000 16.083957
1.751652398 -17.20094528 -4.450623277
Hw 1231 ... (6 Replies)
I tried to use variable inside an array variable, but its not working as expected.:wall:
ENV1=123
ENV1=789
ENV1=120
ENV2=567
if
then
name=ENV1
echo "${name}"
echo "${name}"
echo "${name}"
else
name=ENV1
echo "${name}"
fi
Output: ./val.sh 1
123 (2 Replies)
Hello experts,
I'm stuck with this script for three days now. Here's what i need.
I need to split a large delimited (,) file into 2 files based on the value present in the last field.
Samp: Something.csv
bca,adc,asdf,123,12C
bca,adc,asdf,123,13C
def,adc,asdf,123,12A
I need this split... (6 Replies)
I have a file
root@server # cat /root/list12
11.22.33.44
22.33.44.55
33.44.55.66
33.44.55.66
33.44.55.66
I try to pass to array and display unique.
root@server# cat /root/test12.sh
#!/bin/bash
#delcare array badips and accumulate values to array elemenrs
badips=( $( cat... (4 Replies)
Hello I have the file df.tmp
FS is actually the / FS but escape character\ and end of line $ is used in order to fetch exctly / and not other filesystems.
awk '/\/$/ {print $(NF-1)+0}' df.tmp will work properly and return a value eg. 60
but when I am trying to issue the command with the array... (3 Replies)
i just want to dump my array and see if it contains the values i am expecting. It should print as follows,
ignore=345fht
ignore=rthfg56
.
.
.
ignore=49568g
Here is the code. Is this even possible to do? please help
termReport.pl < $4 | dos2ux | head -2000 | awk '
BEGIN... (0 Replies)
I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be??
e.g. running time strings through an array and trying to examine just minutes:
12:25:30
10:15:13
08:55:23
awk '
NR==FNR{
... (2 Replies)
hi All,
I have a array as follows,
array1=("xx" "abc" "def" "xyz")
and each array1 is also storing some array values, like
array1=abc
and abc=("a" "b" "c") etcetera etcetra.........
Note : each subarray under array1 have index 3 i.e. it can max contain 3 values
if i echo ${abc} ... (5 Replies)
set -A arr a1 a2 a3 a4
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS
integer j=0
for loop in ${arr}
do
printf "array - ${arr}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END
=========
this is not giving me correct output.
I... (5 Replies)