I have a code block as follows in a file:  BalancerMember http://snode1:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode1 BalancerMember http://snode2:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode2   I want to search for all lines which had tc_ keyword and add status=D at the end of those lines. So, the above entries will become like this  BalancerMember http://snode1:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode1 status=D BalancerMember http://snode2:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode2 status=D   I am using the following command to achieve this:  sed -i '/tc_/a status=D' app.conf   But I can see status=D is being after a newline. I don't want a newline for this. It should be appended with a '' (space) .
121845
inputs:  line1 with the PATTERN that contains ( )  line2 with the PATTERN that contains ( )  lineN with the PATTERN that contains ( )    outputs:  line1 with the PATTERN that contains ( ) ; line2 with the PATTERN that contains ( ) ; ... lineN with the PATTERN that contains ( ) ;   I tried this:  find . -name "test.txt" -print | xargs sed -i "/PATTERN/ s/$)/); /g"   but it didn't work.
113945
I am trying to fetch data between a range of time intervals from the log file. However, the complete data is not fetched for the end date.  Below is the command used:   sed -n '/26/Nov/2018/,/30/Nov/2018/ p' /path/file.log    The data I am having in the above log file is somewhat like:   192.168.0.123 - - [25/Nov/2018:13:24:59 +0530] "Data 1"  192.168.0.123 - - [26/Nov/2018:13:24:59 +0530] "Data 2"  192.168.0.123 - - [26/Nov/2018:13:25:09 +0530] "Data 3"  192.168.0.123 - - [27/Nov/2018:13:25:09 +0530] "Data 4"  192.168.0.123 - - [27/Nov/2018:13:25:11 +0530] "Data 5"  192.168.0.123 - - [27/Nov/2018:13:25:53 +0530] "Data 6"  192.168.0.123 - - [28/Nov/2018:13:25:53 +0530] "Data 7"  192.168.0.123 - - [29/Nov/2018:13:25:53 +0530] "Data 8"  192.168.0.123 - - [30/Nov/2018:13:25:53 +0530] "Data 9"  192.168.0.123 - - [30/Nov/2018:13:25:53 +0530] "Data 10"  192.168.0.123 - - [01/Dec/2018:13:25:53 +0530] "Data 11"  192.168.0.123 - - [01/Dec/2018:13:25:53 +0530] "Data 12"
44642
Is there an issue with sed and new line character? I have a file test.txt with the following contents    aaaaa   bbbbb   ccccc   ddddd     The following does not work: sed -r -i 's/\n/,/g' test.txt    I know that I can use tr for this but my question is why it seems not possible with sed.     If this is a side effect of processing the file line by line I would be interested in why this happens. I think grep removes new lines. Does sed do the same?
12955
I want to append this text:  &lt;Directory "/var/www/*"&gt;     Order allow,deny     Allow from all     AllowOverride All &lt;/Directory&gt;   to the file /etc/apache2/apache2.conf  I have access via SSH but I don't know how to use VIM. I would like to do this via a command.
68162
doesn't seem to work  The next example would delete everything between "ONE" and "TWO:"   #!/bin/sh sed ' /ONE/ { # append a line     N # search for TWO on the second line      /\n.*TWO/ { # found it - now edit making one line         s/ONE.*\n.*TWO/ONE TWO/     } }' file   i was expecting to delete everything between ONE and TWO.i tried with file where file contains.  [user5@mailserver ~]$ cat file ONE hello TWO   but the output come like   [user5@mailserver ~]$ ./test ONE hello TWO   I was expecting ONE TWO I am trying to make it correct but not able to do.
33653
I have a text in a text file, where I want everything that is between strings like \{{[} and {]}\} to be deleted - including these strings themselves.  These two string can lie on different lines as well as on the same line. In either case,  on the line on which the beginning \{{[} lies, I don't want the text before, i.e. left, of it to be deleted - and the same holds for the text after {]}\}.  Here is an example: Given a text file with the content   Bla Bla bla bla \{{[} more bla bla even more bla bla bla bla.   A lot of stuff might be here.  Bla bla {]}\} finally done.  Nonetheless, the \{{[} show {]}\} goes on.   the script should return another text file with the content  Bla Bla bla bla  finally done.  Nonetheless, the  goes on.   Unfortunately this simple-looking task turned out to be too difficult for me to do with sed. I'm happy with any solution in any language, as long as I don't have to install anything on my standard linux machine (C and some java is already installed).
13702
I am trying to search a file for a pattern and if the it is found I want to see the line and 10 more lines of the result.  so far I have  grep -n pattern file | cut -d: f1    now not sure how to use this out put to do the print with the logic like   sed -n result,(result+10)p file   probably  going to have a few issued if it pattern is in multiple lines.  Any help is appreciated
17165
I'm trying to use sed to edit a config file. There are a few lines I'd like to change. I know that under Linux sed -i allows for in place edits but it requires you save to a backup file. However I would like to avoid having multiple backup files and make all my in place changes at once.  Is there a way to do so with sed -i or is there a better alternative?
85630
I have a text with marker lines like:  aaa --- bbb --- ccc   I need to get a text from the last marker (not inclusive) to EOF. In this case it will be  ccc   Is there an elegant way within POSIX.2? Right now I use two runs: first with nl and grep for the last occurrence with respective line number. Then I extract the line number and use sed to extract the chunk in question.  The text segments may be quite large, so I'm afraid to use some text-adding method like we add the text to a buffer, if we encounter the marker we empty the buffer, so that at EOF we have our last chunk in the buffer.
104748
Right now I'm using echo &quot;Hello World&quot; &gt;&gt; file.txt  to append some text to a file but I also need to add text below a certain string let's say [option], is it possible with sed? EG: Input file Some text Random [option] Some stuff  Output file Some text Random [option] *inserted text* Some stuff
14743
To all the 'sed' doctors out there:  How can you get 'sed' to extract a regular expression it has matched in a  line?   In other words words, I want just the string corresponding to the regular  expression with all the non-matching characters from the containing line stripped away.  I tried using the back-reference feature like below  regular expression to be isolated           gets `inserted`                here                     |                v    sed -n 's/.*\( \).*/\1/p    this works for some expressions like   sed -n 's/.*\(CONFIG_[a-zA-Z0-9_]*\).*/\1/p    which neatly extracts all macro names starting with 'CONFIG_ ....' ( found in some '*.h' file ) and prints them all out line by line             CONFIG_AT91_GPIO           CONFIG_DRIVER_AT91EMAC                    .                    .              CONFIG_USB_ATMEL           CONFIG_USB_OHCI_NEW                    .                  e.t.c.    BUT the above breaks down for something like    sed -n 's/.*\([0-9][0-9]*\).*/\1/p    this always returns single digits like                    7                  9                  .                  .                    6   rather than extracting a contiguous number field such as.                 8908078               89670890                    .                  .                    .                23019                     .                e.t.c.     P.S.: I would be grateful to feedback on how this is achieved in 'sed'.        I know how to do this with 'grep' and 'awk'       I would like to find out if my - albeit limited - understanding of        'sed' has holes in it and if there is way to do this in 'sed' which I       have simply overlooked.
44258
I am looking for a way to add some string to the beginning of every line (same string for every line). Not something customizable but rather something that will be easy to remember and available on every POSIX-compliant platform (and every shell as well).
112657
I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it.  I have a file with contents like  AAA B C DDD FOO BAR   by which I only mean it has several lines and each line may or may not have spaces.  I want to run a command like  cmd AAA "B C DDD" "FOO BAR"   If I use cmd $(&lt; file) I get  cmd AAA B C DDD FOO BAR   and if I use cmd "$(&lt; file)" I get  cmd "AAA B C DDD FOO BAR"   How do I get each line treated a exactly one parameter?
111755
I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurrence: 1. If this pattern is found in the para, I need to print the entire paragraph. Note that the paragraphs are separated by 2 new line characters.  I have tried the below line of code and this obviously prints the first occurrence in the file. I am somehow unable to use a loop and print all such occurrences.  sed -n '1,/Occurrence: 1/p' ystdef.txt | tail -9 &gt; ystalarm.txt   Can I use the g (global) flag with sed to make this work? If yes, how?  Note that I am aware of the grep -A/B/C commands but they wont work on my Cygwin terminal.
87142
I have this:  sed -i '/^$/d' temp_spec.rb   which is stripping blank lines and works well.  How can I make it only do this for lines 5-999 (or ideally 5 to end-of-file).  I tried:  sed -n5,999 -i '/^$/d' temp_spec.rb sed '5,999!d/^$/d' temp_spec.rb   but neither worked (no errors).
79489
want to search string and need part of string  file.txt:  CREATE MULTISET TABLE $$ENV$$_TEMP_ESM.EMPASGMTAMPTMPRTRSE, NO FALLBACK ,      NO BEFORE JOURNAL,      NO AFTER JOURNAL,      CHECKSUM = DEFAULT,      DEFAULT MERGEBLOCKADSRATIO   while using below sed command getting extra value  Output:   bash-4.3$ sed -n 's/.*$$ENV$$_//p' file.txt  **TEMP_ESM.EMPASGMTAMPTMPRTRSE** ,NO FALLBACK ,   I need only TEMP_ESM.EMPASGMTAMPTMPRTRSE
15144
I'm trying to use sed to remove the rest of a line after:  HTTP1.1" 200  I can't figure out how to get sed to understand I want that whole thing as a string to match, including the double quote and the space.  An example for good measure, I want to turn:  "GET /images/loading.gif HTTP/1.1" 200 10819 "https://...   into   "GET /images/loading.gif HTTP/1.1" 200