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
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 01:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy