LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2015, 12:29 AM   #1
pump1t
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Rep: Reputation: Disabled
Need help with sed


I have config below:
location /c21p/ {
proxy_pass http://acq_c21connect/acq_c21p/; #DIRECTS TO Prod instance
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_redirect default;

I wanted to search for 'location /c21p/' and if found add this line "proxy_buffering off;" at the end of the block, so the output will be:

location /c21p/
proxy_pass http://acq_c21connect/acq_c21p/; #DIRECTS TO Prod instance
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_redirect default;
proxy_buffering off;

tried using this sed command, but didnt work:
sed -e "/'location /c21p/' {N;N;N;s/$/\'proxy_buffering off';}" acq_chris21.com.conf > acq.txt

Last edited by pump1t; 05-06-2015 at 12:48 AM.
 
Old 05-06-2015, 01:56 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
So what you have show is the entire file?
Does the added line need to be after 'proxy_redirect default;'?
Is there a closing curly brace? ie } to match the opening one on the location line?

Please explain what the following is meant to do?
Code:
/'location /c21p/'
I ask as there are no single quotes in your example file and // tells sed to look for what is between them yet you have ///, which I would think would confuse sed??

Please also use [code][/code] tags around code and data to make it clearer and easier to read.
 
Old 05-06-2015, 02:08 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,050

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
Note also the opening curly has disappeared in the (wanted) output.
Very confusing before even attempting to parse the sed.

Personally I'd probably use awk - if I knew what was really wanted.
 
Old 05-08-2015, 01:23 AM   #4
pump1t
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
this didn't help, what I wanted to happen is to search for:

"location /c21p/" in the input file and add "proxy_buffering off;" to the last entry before the "}", eg:

output will be:

location /c21p/ {

....
....
....
proxy_buffering off;
}
 
Old 05-08-2015, 01:57 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,508

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
you need to use \ here and do not need '
Code:
# instead of:
sed -e "/'location /c21p/' 
#
sed -e "/location \/c21p/
please do not reply "this didn't help", this is not the full solution. I suggest you to use awk too.
 
1 members found this post helpful.
Old 05-08-2015, 05:34 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
In fairness to syg00 and myself, we are trying to help, but the poor quality of the request made that difficult so we were trying to get more information from you to help us to help you.

As has been suggested, and now aided with your additional information, awk would be better suited as you can provide the record separator (RS) to be your curly braces.
Now this would initially assume that there are no additional curly braces found inside, ie. could you have:
Code:
location /c21p/ {
....
..some text{ some more } ..
....
}
If above is a possible scenario you would need to be cautious building your regex for the RS argument.

As you may now see, what seems crystal clear to you may illicit more questions from those of us who are not looking at what you are and if you do not paint an appropriate picture we may provide
information that is of no help.

To finish, are you familiar with awk and can go from here?

awk manual
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
create file list: SED inline vs SED standalone, enormous speed difference Corsari Linux - Newbie 4 09-02-2013 04:01 AM
[Cygwin, sed] Using filenames as both files and search strings within sed lingh Linux - Newbie 5 10-20-2012 11:38 AM
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 01:27 PM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 08:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


All times are GMT -5. The time now is 06:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration