I'm messing around with sed for fun and have a little function I found that replaces a few characters:  sed 's/"p"$/0/;s/"e"/1/' sedtext.txt   Where sedtext.txt is as follows:  1, 2, 6, 7, "p"  1, 6, 7, 2, "e"    When I do the following I get the desired output:  sed 's/"p"$/0/;s/"e"/1/' sedtest.txt &gt; sedtest2.txt    But when I try to overwrite the input file with the output I get a blank file:  sed 's/"p"$/0/;s/"e"/1/' sedtest.txt &gt; sedtest.txt    Why is this the case?
10964
I often see tutorials online that connect various commands with different symbols. For example:  command1 |  command2 command1 &amp;  command2 command1 || command2     command1 &amp;&amp; command2   Others seem to be connecting commands to files:  command1  &gt; file1 command1  &gt;&gt; file1   What are these things? What are they called? What do they do? Are there more of them?    .
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?
45974
When using sed to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)?  For instance, how can I change the command line  find . -type f | xargs sed -i 's/abc/def/g'   so I can see the changes that are made on the fly?
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
73286
I have a file that contains multiple lines of xml. I would like to replace certain parts of the file. Some parts of the file contains quotation marks (") which I would like to replace. I have been trying to escape the quotation mark with \, but I don't think this is working based on the result of my file.  Here is an example of one of my sed commands:  sed -e "s/\"text\"/'text'/ig" file.xml &gt; temp.tmp   Is this how you escape quotation marks in a sed command or am I doing something wrong?
122795
I have a requirement like i have to remove the strings or numbers between two Parenthesis in a file. I used sed command but it is working on a single line. My opening Parenthesis is in one line and the closing parenthesis is in other line. How can i do it?  I tried this command using sed:  sed -e 's/([^()]*)//g'   but this works only when My opening and closing parenthesis are on the same line.  For Example:-  Input file:  select a ,b ,c FROM ABCD (select e ,f ,g ,h FROM XYZ)   Output should be:  select a ,b ,c FROM ABCD
62598
How to replace the third occurrence of the string in the file using sed command. Example: Change only the third occurrence of is to us in the file. My input file contains: hai this is linux. hai this is unix. hai this is mac. hai this is unchanged.  The expected output is: hai this is linux. hai thus is unix. hai this us mac. hai this is unchanged.
34368
I'm trying to take the contents of a file and insert it after a matching pattern in another file using sed. My question is very similar to , but I wish to insert the contents of a file inline rather than on a new line. How can I do this?  Using the example question I referenced, the first answer does exactly what I want; however, I want the insertion to happen inline:  sed '/First/r file1.txt' infile.txt    The actual data I want to insert is a JSON file:  [     {         "foo": "bar",          "baz": "biff",         "data": [             {                 "a": 1945619,                  "b": [                     {                         "c": 512665,                          "d": "futz"                     }                 ]             }         ]     } ]
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.
60690
I have a txt file  123 456 789 456 123456   I want to delete specific characters from the file i.e (123).  I tried with  $ sed -i '/123/d' dummy.sh $ vi dumm.txt 456 789 456   In the below command when I run both the words (123 and 123456) are getting deleted but I need to delete only 123 from the file   $ sed -i 's/123//g' dummy.sh $ vi dumm.txt 456 789 456 456   when I run the below command the 123 is getting replaced with null.  Can anyone say how to delete a whole line if it contains only specific number?
90874
To print part of the string, replace , with . I use command:  echo "${q:16:6}" | sed 's/,/./'   Is it possible to use something like:  echo "${q:16:6/,/.}"   because it does not work?
19044
I execute a sed command in my script:  sed -i "${1}s/${2}=.*/${2}=${REPLY}/" $3   this is the echo:  sed -i 13s/log4j.appender.ROOT2.File=.*/log4j.appender.ROOT2.File=/app/TET/log.log/ /applis/DIAPASON/diapason1/conf/log4j.properties   My error:  sed: -e expression n°1, character 61: unknown option fors`'
26804
I'm so confused with GNU sed, POSIX sed, and BSD sed's myriad of options.  How do I replace literal \n with the newline character using these three sed types?
26992
I have this file:  sometext1{ string1 }  sometext2{ string2 string3 }  sometext3{ string4 string5 string6 }   I want to search this file for a specific string and print everything before this string up to the opening { and everything after this string up to the closing }. I tried to achieve this with sed but if I try to print everything in the range /{/,/string2/ for example sed prints this:  sometext1{ string1 }  sometext2{ string2 sometext3{ string4 string5 string6 }   If I search for the string "string2" I need the output to be:   sometext2{ string2 string3 }   Thanks.
100128
Here's a sample 'test.txt'  abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das   sample desired output:  X1yad X2fad X3had X4wad X5mad   I could get it working in vim with:  :% s/\v.*(X\d)(.*)45.*/\1\2/   and worked in perl as well with:  open(my $file, "&lt;", "test.txt"); while(&lt;$file&gt;) {     s/.*(X\d)(.*)45.*/$1$2/;      print $_; }   my eventual regular expression needs two groupings, it wasn't required for this example output  am not able to get it work with sed:  sed -r 's/.*(X\d)(.*)45.*/\1\2/' test.txt abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das   just to check sed is working,  sed -r 's/(a)/#\1#/' test.txt #a#bcdX1yad45das #a#bcdX2fad45das #a#bcdX3had45das #a#bcdX4wad45das #a#bcdX5mad45das   what am I doing wrong in sed?
69314
I have several big files with some measurements.   It looks this way:  N 12344;PE 9.9999999;... #S 0 0 31 44 75 130 165 196... #S_+ "2 5 2 3 3 1 1 2 3 1 2 2...  N 12345;PE 9.9999999;... #S 0 0 34 57 84 133 152... #S_+ "1 0 1 1 2 3 0 0 0...  N 12346;PE 9.9999999;... #S 0 0 31 44 73 140 169... #S_+ "3 3 4 0 0 2 1 2 4...  N 25104;PE 9.9999999;... #S 0 0 36 52 102 108 145... #S_+ "1 1 0 1 0 0 3 0 1...  N 25105;PE 9.9999999;... #S 0 0 32 58 88 130 143...   Sample is here:   The file is much bigger but I replaced part of the data with "..." to make it shorter.  I need to somehow replace the line ends before "#S" - in fact simply merge the "N" line with the following two ones into one line (or with the following three ones so I can get rid of the blank lines). Expect output like this:  N 12344;PE 9.9999999; #S 0 0 31 44 75 130 165 196 #S_+ "2 5 2 3 3 1 1 2 3 1 2 2... N 12345;PE 9.9999999; #S 0 0 34 57 84 133 152 #S_+ "1 0 1 1 2 3 0 0 0... N 12346;PE 9.9999999; #S 0 0 31 44 73 140 169 #S_+ "3 3 4 0 0 2 1 2 4... N 25104;PE 9.9999999; #S 0 0 36 52 102 108 145 #S_+ "1 1 0 1 0 0 3 0 1... N 25105;PE 9.9999999; #S 0 0 32 58 88 130 143...   Is this possible to achieve using some command-line utility in linux?   My knowledge is quite limited in this area so I would appreciate any help.  thanks
105512
I can't find any documentation about the sed -e switch, for simple replace, do I need it?  e.g.  sed 's/foo/bar/'   VS  sed -e 's/foo/bar/'