QUERY_STRING with multiples appearances of the same string prefix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting QUERY_STRING with multiples appearances of the same string prefix
# 1  
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

# 2  
Old 02-25-2010
If I understand your question you want to make a html file with the content of the QUERY_STRING.

Perhaps there's an easier approach to get the result.

How should the file looks like with the given QUERY_STRING?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question