Sponsored Content
Top Forums Shell Programming and Scripting QUERY_STRING with multiples appearances of the same string prefix Post 302398453 by numele on Wednesday 24th of February 2010 08:41:29 PM
Old 02-24-2010
QUERY_STRING with multiples appearances of the same string prefix

I have a shell script and it works pretty well to pull out the query_string contents of a single instance of router=

But if I have multiple router= strings, it only pulls out the last one.

Is there a way to pull out every router= and if there is a multple string, to egrep them together under $CISCO


Code:
http://routerlog.cgi?router=router1-fa6-0.amrltx&router=router1-fa6-0.aus2tx&router=router2-fa6-0.aus2tx&router=router1-fa6-0.bkfdca&month=02&day=24&shour=12&sminute=00&ehour=23&eminute=59&string=

Code:
#!/bin/sh
echo "Content-type: text/html\n"
echo ""
CISCO=`echo "$QUERY_STRING" | sed -n 's/^.*router=\([^&]*\).*$/\1/p'`
MONTH=`echo "$QUERY_STRING" | sed -n 's/^.*month=\([^&]*\).*$/\1/p'`
DAY=`echo "$QUERY_STRING" | sed -n 's/^.*day=\([^&]*\).*$/\1/p'`
PMONTH=`date +%m`
PDAY=`date +%d`
if [ $MONTH = $PMONTH ] && [ $DAY = $PDAY ] ; then 
SYSLOG="cat braslog"
else
SYSLOG="zcat braslog.$MONTH.$DAY.gz"
fi
SHOUR=`echo "$QUERY_STRING" | sed -n 's/^.*shour=\([^&]*\).*$/\1/p'`
SMINUTE=`echo "$QUERY_STRING" | sed -n 's/^.*sminute=\([^&]*\).*$/\1/p'`
EHOUR=`echo "$QUERY_STRING" | sed -n 's/^.*ehour=\([^&]*\).*$/\1/p'`
EMINUTE=`echo "$QUERY_STRING" | sed -n 's/^.*eminute=\([^&]*\).*$/\1/p'`
STIME="$SHOUR:$SMINUTE"
ETIME="$EHOUR:$EMINUTE"
STRING=`echo "$QUERY_STRING" | sed -n 's/^.*string=\([^&]*\).*$/\1/p' | \
sed -e "s/+/ /g" -e "s/%22/\"/g" -e "s/%2C/,/g" -e "s/%2F/\//g" -e "s/%3A/\:/g" -e "s/%26/\&/g" -e "s/%7C/|/g"`
echo "<html>"
echo "<body>"
if [ -z "$STRING" ] ; then
results=`$SYSLOG | egrep "$CISCO" | nawk '$3>=from&&$3<=to' from="$STIME" to="$ETIME" | nawk 'sub("$", "<br>")'`
else
results=`$SYSLOG | egrep "$," | egrep -i "$STRING" | awk '$3>=from&&$3<=to' from="$STIME" to="$ETIME" | nawk 'sub("$", "<br>")'`
fi
echo $results
echo "</body></html>"



---------- Post updated at 05:15 PM ---------- Previous update was at 04:10 PM ----------

I wanted to add the router= string will change on each submission. Sometimes just one router and other times there will be many. Each with a different router name.

---------- Post updated at 07:41 PM ---------- Previous update was at 05:15 PM ----------

I found a rather crude way of putting my multiple same prefix strings in a file. Any suggestions to clean this up?

Code:
echo "$QUERY_STRING" | nawk 'gsub(/&/,"\n")' | sed -n 's/^router=\([^&]*\).*$/\1/p' > query.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to cut prefix from a string?

Hi folks, I have the following parameter setting: export ADMIN_HOST_NAME=http://hostname.com I want to define a new parameter,ADMIN_HOST_NAME_NEW,which based on $ADMIN_HOST_NAME but I need to remove the prefix "http://". The requested result for $ADMIN_HOST_NAME_NEW is hostname.com How... (2 Replies)
Discussion started by: nir_s
2 Replies

2. Shell Programming and Scripting

Prefix a string to the contents of a file

Hi all, I have a requirement where in i have to create a temporary file by prefixing a string of special characters to each row of a input file. the input file is '|' delimited. here is the content of input file aaa|1234|axad|123 bbb|qwqw|qw|1334 the output should be ... (5 Replies)
Discussion started by: nvuradi
5 Replies

3. UNIX for Dummies Questions & Answers

how to cut prefix from a string

I have a file: chromosome1:436728 chromosome2:32892 ..... chromosome22:23781 I just want to get the number, not the prefix "chromosomeX", so I want to remove all the prefix ahead of the numbers. How can I do that?? Thanks!!! (PS: give me some very simple command so that I can understand... (4 Replies)
Discussion started by: kaixinsjtu
4 Replies

4. Shell Programming and Scripting

Bash script pulling variable from query_string

I have a variable embedded in a long string called "commands" coming in on a query_string. I need to copy the string to a file with the variable $loop1 converted before it writes. Right now, it writes the varible itself instead of what it should be. QUERY_STRING... (2 Replies)
Discussion started by: numele
2 Replies

5. Programming

multiples of 10 in java

Hi Guys, I wonder how can I determine when a given number is a multiple of another one in java. Let's say if I have 27 how can I determine whether is multiple of 5 using java programming. Thanks. (1 Reply)
Discussion started by: arizah
1 Replies

6. Shell Programming and Scripting

Replace prefix and suffix of a string

Hi, I'm new about shell scripting, and I need to do something like abcd **1234** efgh by abcd '''1234''' efgh I know that command sed helps about change one string by another, but I dont know how to keep whatever is inside **_** and replace * with '. Thanks! (5 Replies)
Discussion started by: selvaya
5 Replies

7. Shell Programming and Scripting

How can I get the 3 consecutive appearances of a line?

File 1 aaa ccc fff File 2 aaa bbb ddd File 3 aaa bbb eee File 4 (4 Replies)
Discussion started by: Misa-Misa
4 Replies

8. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

9. Shell Programming and Scripting

Removing only Prefix string (!)

Hello everyone, I want to remove only prefix ME_ from all the values that are present in the FILEA. Below code I'm using for this. sed 's/ME\_//g' FILEA > FILEB Using the above code, all ME_ values are getting removed from the file. But the problem here is I want to remove only Prefix ME_... (4 Replies)
Discussion started by: ed_9
4 Replies

10. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies
ROUND(3)								 1								  ROUND(3)

round - Rounds a float

SYNOPSIS
float round (float $val, [int $precision], [int $mode = PHP_ROUND_HALF_UP]) DESCRIPTION
Returns the rounded value of $val to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default). Note PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings. PARAMETERS
o $val - The value to round o $precision - The optional number of decimal digits to round to. o $mode - Use one of the following constants to specify the mode in which rounding occurs. +--------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +--------------------+---------------------------------------------------+ | | | | PHP_ROUND_HALF_UP | | | | | | | Round $val up to $precision decimal places away | | | from zero, when it is half way there. Making 1.5 | | | into 2 and -1.5 into -2. | | | | | | | |PHP_ROUND_HALF_DOWN | | | | | | | Round $val down to $precision decimal places | | | towards zero, when it is half way there. Making | | | 1.5 into 1 and -1.5 into -1. | | | | | | | |PHP_ROUND_HALF_EVEN | | | | | | | Round $val to $precision decimal places towards | | | the next even value. | | | | | | | |PHP_ROUND_HALF_ODD | | | | | | | Round $val to $precision decimal places towards | | | the next odd value. | | | | +--------------------+---------------------------------------------------+ RETURN VALUES
The rounded value EXAMPLES
Example #1 round(3) examples <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?> Example #2 $mode examples <?php echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9 ?> Example #3 $mode with precision examples <?php /* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5 /* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5 /* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5 /* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5 ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $mode parameter was introduced. | | | | | 5.2.7 | | | | | | | The inner workings of round(3) was changed to | | | conform to the C99 standard. | | | | +--------+---------------------------------------------------+ SEE ALSO
ceil(3), floor(3), number_format(3). PHP Documentation Group ROUND(3)
All times are GMT -4. The time now is 11:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy