I'm trying to edit a file on a remote server via a terminal and to make a change in said file I have to (or have used so far) use the 'sed' command.  in the below file i want to delete the string STUFF_456 and its new line character.  STUFF_123 STUFF_456 STUFF_789   However when I use this command in sed i'm left with a blank line.  $ sed -i 's/STUFF_456//' /file/path/here.txt STUFF_123  STUFF_789   I need to get rid of the blank line and keep the other two entries.  How can I accomplish this?
122203
I have a Bash script that writes data into a log file, then from that I take out stuff I want using the sed command. That gives me a file data.txt. What I want to know is how I go about deleting specific line inside that data.txt file.  For example:  123 456 789   I want to remove the 2nd line, containing 456 so that I only have  123  789   I tried with sed '2d' data.txt but it doesn't work.  I use this command to create data.txt from log.log:  sed -nE '1s/.{1}(.{2}).*/\1/p;' log.log &gt;&gt; data.txt
98042
I'm reading a lot of documentation on sed, and am still stumped on my particular use case.  I want to replace this line in a conf file with my own line:  Replace this line: #maxmemory &lt;bytes&gt; with: maxmemory 26gb  This is what I tried:  sed s/maxmemory.*bytes.*/maxmemory 26gb/ /etc/redis/redis.conf  I get the error: sed: -e expression #1, char 30: unterminated `s' command  Which stumps me because I don't know what that means. So my question is:  How can I accomplish what I want? What does that error mean? (so I can learn from it)
50199
I'm a relative Linux novice.  Suppose that I have a text file a.txt that contains the following text:  A B C   Now, if I want to change the text on line 2 (which contains B), I can use the following sed command:  sed -i '2s/^.*$/X/' a.txt   to change the B to X, for example.  But now suppose that I want to write an sed command that changes the text on line 2 to something that includes a bash string variable.  I want to change the text on line 2 to fname="myaddress", where the quotation marks are included explicitly, and where myaddress is a bash string variable (defined somewhere else).  To try to do this, I have created a bash shell script called mytest.sh and containing the following:  #!/bin/bash  myaddress="/home/" echo fname=\"$myaddress\"  head a.txt sed -i '2s/^.*$/fname=\"$myaddress\"/' a.txt head a.txt   Now, echo fname=\"$myaddress\" prints fname="/home/", which is the text that I want to be on line 2 of a.txt.  However, sed instead prints fname="$myaddress" to line 2 of a.txt, probably because it is inside the surrounding apostrophes.  In other words, the output of the above bash shell script is:   fname="/home/" A B C  A fname="$myaddress" C   My question is, how can I get sed to actually print the value stored in myaddress and referenced by $myaddress?
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"                     }                 ]             }         ]     } ]
116749
I have been told it was possible, but without a single working example, that sed can read from a string variable without need for an input file. I have yet to get it to work.  For general safety, I’m writing the $PATH variable to another variable, as I mess with this, because I don’t need other problems to arise until I know exactly how to do this.  Consider the following:  ~$x=$PATH ~$sed -i 's/:/ /g' $x   this fails with: No such file or directory.  Here are some others I have tried:  ~$ sed -i 's/:/ /g' | (read x)  sed: no input files ~$ sed -i 's/:/ /g' | (read $x)  bash: read: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier sed: no input files ~$ sed -i 's/:/ /g' | $(read x)  sed: no input files ~$ sed -i 's/:/ /g' | $(read $x)  bash: read: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier sed: no input files ~$ sed -i 's/:/ /g' &lt; $(read $x)  bash: read: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier bash: $(read $x): ambiguous redirect ~$ sed -i 's/:/ /g' &lt; read $x  bash: read: No such file or directory ~$ sed -i 's/:/ /g' &lt; (read x)  bash: syntax error near unexpected token `(' ~$ sed -i 's/:/ /g' &lt; $((read x))  bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games: syntax error: operand expected (error token is "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games") ~$ sed -i 's/:/ /g' &lt; $((read $x))  bash: read /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games: division by 0 (error token is "usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games") ~$ sed -i 's/:/ /g' &lt;&lt; $((read $x))  &gt; ;^C ~$ sed -i 's/:/ /g' &lt;&lt; $(read $x) &gt; ;^C ~$ sed -i 's/:/ /g' $x sed: can't read /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games: No such file or directory ~$ sed -i 's/:/ /g' &lt; $x bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games: No such file or directory ~$ sed -i 's/:/ /g' &lt; echo $x bash: echo: No such file or directory ~$ sed -i 's/:/ /g' |  echo $x /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games sed: no input files   Can this even work? I would prefer not to need to write files I don't need just so I can use sed. For this particular example, if ~$x=$PATH ~$sed -i 's/:/ /g' $x actually worked the way I would have hoped, I would get:   /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games   which I could then assign to a variable, and use in future commands, like ls $x
115378
How do I replace a string I1Rov4Rvh/GtjpuuYttr== with mytest in a file mtestsed.properties with sed command?   I have tried:  sed -e -i 's/I1Rov4Rvh/GtjpuuYttr==/mytest/g' mtestsed.properties
94078
I have a text file (devel.xml).  I added the word REPLACETHIS to it in order to replace this string with the content within a different file (temp.txt).  The closest thing I have is this:  sed -i -e "/REPLACETHIS/r temp.TXT" -e "s///" devel.txt;   This inserts the content after the string, and then deletes the string afterwards.  Is this the best way to do it?
34120
I am looking for a way to replace a string in a file with a string that contains a slash by using sed.  connect="192.168.100.61/foo" srcText="foo.bar=XPLACEHOLDERX" echo $srcText | sed "s/XPLACEHOLDERX/$connect"   The result is:  sed: -e Expression #1, Character 32: Unknown option for `s'
51572
I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script:  cat shared.txt sed 's/whatever1/$2 ... whatever2/' &gt; shared2.txt   The result in shared2.txt looks like:  ...$2....   What did I do wrong?
71374
I have a file with a list of emails in it and each line has an email in it. I want to remove lines that contain the string example.com or test.com.  I tried this:   sed -i 's/example\.com//ig' file.txt    But it will remove only the string example.com, how can I remove the entire line?
54821
I know this question has probably been answered before.  I have seen many threads about this in various places, but the answers are usually hard to extract for me.  I am looking for help with an example usage of the 'sed' command.  Say I wanted to act upon the file "hello.txt" (in same directory as prompt).  Anywhere it contained the phrase "few", it should be changed to "asd".  What would the command look like?
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?
21314
I have this output as a result of comparing files with diff:  &lt; IF-Name :STRING: "lns-wall-01-t2"       Index:Gge32: 260 --- &gt; IF-Name :STRING: "lns-wall-01-t2"       Index:Gge32: 25   I need this output:  lns-wall-01-t2 old:260 new:25   I want to use sed.
25041
I am using GNU sed 4.2.2 and after searching cannot find out the reason sed behaves oddly in some situations:  I have a directory with the following:  foofile.txt barfile.txt bazfile.txt config/   Case 1  sed -i 's/foo/bar/g' *.txt   This works as I expect.  It replaces all the "foo"s with "bar"s in the three regular files.  Case 2  sed -i 's/foo/bar/g' * sed: couldn't edit config: not a regular file   It replaces "foo" with "bar" in barfile.txt and bazfile.txt, but not in foofile.txt.  I assume it goes through the list of files expanded from the * alphabetically, and when it hits config/ it errors and exits.  Is there a way to have sed ignore errors and continue processing files?  Case 3  for file in $(find . -maxdepth 1 -type f); do sed -i 's/foo/bar/g' &lt;"$file"; done sed: no input files sed: no input files sed: no input files   Could someone please explain why sed does this?  Why does it say there's no input file when it's being given one?  I know that I can use the following but I'm asking why sed acts this way, not how do I solve this one use case.  find . -maxdepth 1 -type f -exec sed -i 's/foo/bar/g' {} \;
87368
I did tried sed and awk, but its not working as the character involves / which is already there in command as delimiter. Please let me know how can I achieve this. Below is a sample Example. We want to remove the commented sections, i.e /*.....*/ /*This is to print the output data*/ proc print data=sashelp.cars; run; /*Creating dataset*/ data abc; set xyz; run;
122379
I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far:   sed -i '/ * [^()] */d' *.c  This works when the comments are on the same line as an asterisk or backslash.   However it doesn't work when there is a commented line without a slash or asterisk.   I know sed goes line by line, I just don't know how to tell it to keep deleting until it sees a */.
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