Splitting QUERYSTRING with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting QUERYSTRING with sed
# 1  
Old 02-19-2010
Splitting QUERYSTRING with sed

Working on a shell script where in the Query_String I need to separate one of the strings into two. For an example, my string has router=bras1+dallastx and I need to separate bras1 and dallastx into different variables. The DOMAIN variable works but I can not get the CISCO variable going. Any suggestions?

Here is my url that feeds the script:
Code:
http://mywebpage/syslog.cgi?router=router1+dallastx&month=01&day=01&string=security
 
NAME=`echo "$QUERY_STRING" | sed -n 's/^.*router=\([^&]*\).*$/\1/p'`
for opt in $NAME; do
CISCO= `echo $NAME | sed 's/+/ /g' | awk '{print $1}'`
DOMAIN=`echo $NAME | sed 's/+/ /g' | awk '{print $2}'`
done


Last edited by pludi; 02-19-2010 at 02:24 AM.. Reason: code tags, please...
# 2  
Old 02-19-2010
Code:
#! /bin/bash

var="router=bras1+dallastx"
pos=`expr index $var =`
test=${var:$pos}
part1=${test%+*}
part2=${test#*+}
echo $part1 $part2

# 3  
Old 02-19-2010
Thanks SKMDU for the suggestion. Unfortunatley, I tried but it did not work for what I am doing. The router= string will change each time.
# 4  
Old 02-19-2010
Do you mean = wont be there?
# 5  
Old 02-19-2010
I get this from a test

Code:
 
#! /bin/bash
var="router=bras1+dallastx"
pos=`expr index $var =`
test=${var:$pos}
part1=${test%+*}
part2=${test#*+}
echo $part1 $part2
# chmod 755 test123.cgi
# ./test123.cgi
expr: syntax error
router=bras1 dallastx

# 6  
Old 02-19-2010
Try this:
Code:
var="router=bras1+dallastx"

CISCO=$(echo "$var" | awk -F[=+] '{print $2}')
DOMAIN=$(echo "$var" | awk -F[=+] '{print $3}')

With sed:

Code:
CISCO=$(echo "$var" | sed 's/.*=\(.*\)+.*/\1/')
DOMAIN=$(echo "$var" | sed 's/.*+//')

# 7  
Old 02-19-2010
Thanks Franklin52, I used your sed method to solve this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to access QueryString using JavaScript?

I want to access query string properties by key using client side laguage like jquery or javascript. window.location.search will be used but i dont have any idea how i wll be used to get query string parameters. private URL removed (1 Reply)
Discussion started by: grabbitmedia
1 Replies

2. Shell Programming and Scripting

Sed: Splitting A large File into smaller files based on recursive Regular Expression match

I will simplify the explaination a bit, I need to parse through a 87m file - I have a single text file in the form of : <NAME>house........ SOMETEXT SOMETEXT SOMETEXT . . . . </script> MORETEXT MORETEXT . . . (6 Replies)
Discussion started by: sumguy
6 Replies

3. Shell Programming and Scripting

splitting value

Hello, i want to take a one word from my file. -- myfile.txt -- test blablabla suPHP_ConfigPath /home/performe/etc blablabla etc. bla bla. -- myfile.txt -- How can i take performe from this file ? Thank you. (7 Replies)
Discussion started by: SAYGIN
7 Replies

4. Shell Programming and Scripting

Splitting a line with pattern in Sed - Unix

I have a file with single line, that line contains just like the following sample 00200100293^30^1^bla bla ...._______To: zabell00200100293^30^3^aSub00200100293^30^4^ellaCc: Sanders,De on my desk__________00200100293^30^4^___________________________________00A00ABC0293^30^1^something___To: some... (10 Replies)
Discussion started by: Vasan
10 Replies

5. Shell Programming and Scripting

help in splitting

Hi experts, In the lines below I am trying to copy only the words which come after "//" into an array short nloh; // Comments int age; // Age of the person Please help me in achieving this After the code, the output of the array should Comments Age of the person (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

6. UNIX for Dummies Questions & Answers

Help with splitting a string..

Hello I need help with the following. I have strings like #if defined(__def1__) #if defined(__def1__) || defined(__def2__) #if defined(__def1__) && defined(__def2__) && defined(__def3__). #if defined(__def1__) || defined(__def2__) || defined(__def3__). I need to print what is there in... (4 Replies)
Discussion started by: srk
4 Replies

7. Linux

awk/sed for splitting a field into two

I have a tab delimitted dataset with 4 fields. I like to split the second field into two, and have 5 fields. I like to remove the "-" sign when I get a new fiel. would you help? It is like: 1223 100-5 rr dd I need it like: 1223 100 5 rr dd (2 Replies)
Discussion started by: sire
2 Replies

8. AIX

Splitting the File

Hello I have a requirement where i have to split the file into number of files. Lets say i have 200 records and i need to split the file with 50 records each which would be 4 files. If the file has 60 records then first 50 records in first file and then rest of the 10 records in second file. if... (3 Replies)
Discussion started by: dsdev_123
3 Replies

9. Shell Programming and Scripting

splitting a file

I have a huge file with 13 million records , how do i split this file into 13 files which has 1 million records in each ( each record is one line) I tried this but how to print the second million etc cat file | head -1000000 > file1 cat file | tail -1000000 >file13 please shed some... (1 Reply)
Discussion started by: ramky79
1 Replies

10. Shell Programming and Scripting

Splitting text file to several other files using sed.

I'm trying to figure out how to do this efficiently with as little execution time as possible and I'm pretty sure using sed is the best way. However I'm new to sed and all the reading and examples I've found don't seem to show a similar exercise: I have a long text file (i'll call it... (3 Replies)
Discussion started by: JeffV
3 Replies
Login or Register to Ask a Question