sed replace spaces between quotes with a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed replace spaces between quotes with a variable
# 1  
Old 03-06-2010
Java sed replace spaces between quotes with a variable

I have lines with:

Code:
elseif (req.http.host ~ "^(www.)?edificationtube.com$|www.edificationtube.org www.edificationtube.net edificationtube.org www.edificationtube.com edificationtube.net") {
elseif (req.http.host ~ "^(www.)?collegecontender.com$|www.collegecontender.com collegecontenders.com www.collegecontenders.com") {
elseif (req.http.host ~ "^(www.)?adaxle.com$|www.adaxle.net www.adaxle.com adaxle.net www.adaxle.org www.adaxle.biz adaxle.org adaxle.biz") {

Within a txt file, I want a sed command that would go through only lines that contain "req.http.host", but only replace the spaces within those lines it finds between the quotes, so the end result would look like:

Code:
elseif (req.http.host ~ "^(www.)?edificationtube.com$|www.edificationtube.org|www.edificationtube.net edificationtube.org|www.edificationtube.com|edificationtube.net") {
elseif (req.http.host ~ "^(www.)?collegecontender.com$|www.collegecontender.com|collegecontenders.com|www.collegecontenders.com") {
elseif (req.http.host ~ "^(www.)?adaxle.com$|www.adaxle.net|www.adaxle.com|adaxle.net|www.adaxle.org|www.adaxle.biz|adaxle.org|adaxle.biz") {

Can anyone guide me on how this can be done with sed/awk?

Thanks!
# 2  
Old 03-06-2010
This will replace the space after .com .net or .org with a pipe.
Code:
 sed '/req.http.host/s/\([com|net|org]\) /\1|/g' file

# 3  
Old 03-07-2010
That gives me the output of:

Code:
       elseif (req.http.host|~ "^(www.)?labourtv.net$|www.myertec.co.uk myertec.co.uk www.labourtv.net") {

Close, but I don't want it to add an extra | between host and ~, I just want it on every space between the quotes to add a pipe (|).

Let me know if its possible here.

Thanks.
# 4  
Old 03-07-2010
Code:
awk -F "\"" '/req.http.host/ {gsub(/ +/, "|",$2)}1' OFS="\"" urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spaces in double quotes in variable ?

Hi got this issue and was wondering if someone could please help out ? var='." "' echo $var ." " I 'll get ." " and not ." with 10 spaces in between " Thanks (3 Replies)
Discussion started by: stinkefisch
3 Replies

2. UNIX for Beginners Questions & Answers

sed command to replace consecutive double quotes

I need to replace consecutive double quotes in a csv file, the data in the file is enclosed in double quotes but there are some places where the quotes are repeating Example is below Incoming data is : "Pacific Region"|"PNG"|"Jimmy""|""| Need output as: "Pacific... (10 Replies)
Discussion started by: abhilashnair
10 Replies

3. Shell Programming and Scripting

Replace delimeter between quotes with \| using sed or awk

I've a pipe delimited data in a file of size 3GB. if the text data conatins pipe delimiter that will be enclose with double quotes. I have to replace delimiter which exists between double quotes with #%@#%@#%@ using awk or sed. can some one provide a better and efficient solution to me. The below... (4 Replies)
Discussion started by: BrahmaNaiduA
4 Replies

4. UNIX for Dummies Questions & Answers

Need help with sed replace script to include spaces

I've got a sed shell script I've been using for quite a while to do batch find/replace operations on .xml files containing various types of text entries. This is the script I use: #!/bin/bash while read text_old text_new; do sed_script+="s/$text_old/$text_new/g;" done < trans_old_to_new... (9 Replies)
Discussion started by: Agreppa
9 Replies

5. Shell Programming and Scripting

sed command to replace string that contain blackslash,double quotes

Hi All, I have been trying to replace a string using the sed command string value contain blackslash and double quotes. I am not a expert writer of unix script but do try not to ask question. I have almost given up. Hope you all can give me some suggestion I want to replace a place string... (6 Replies)
Discussion started by: thanush9sep
6 Replies

6. Shell Programming and Scripting

sed replace one space and leave other spaces untouched

Hi Friends, I looked up online, but couldn't figure out a proper solution. I have an input file where the columns are separated by multiple spaces and the column content is separated by single space. For example, Chr1 hello world unix is fun In the above example, chr1 is first... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

Hi I have written a shell script which used sed code below sed -i 's/'"$Pattern"'/ /g' $FileName I want to count the length of Pattern and replace it with equal number of spaces in the FileName. I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Discussion started by: rakeshkumar
8 Replies

8. Shell Programming and Scripting

HELP with AWK or SED. Need to replace the commas between double quotes in CSV file

Hello experts, I need to validate a csv file which contains data like this: Sample.csv "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 I just need to check if all the records contain exactly the number of... (5 Replies)
Discussion started by: shell_boy23
5 Replies

9. Shell Programming and Scripting

How to replace spaces excluding those within double quotes and after backslash?

In bash or perl, I would like to know how to substitute a null character (0x00) for every white space without changing the white spaces inside the block of double quotes and the white space immediately following a backslash. Suppose that sample.txt consists of the following line. "b 1" c\ 2 ... (2 Replies)
Discussion started by: LessNux
2 Replies

10. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies
Login or Register to Ask a Question