Situation:  echo "tell me a word" read the_word   How to replace all WordToReplace in a file by the_word?  sed does not seems to appreciate:  sed -i 's/WordToReplace/$the_word/g' thefile.sh
4793
I want to do:  cat update_via_sed.sh | sed 's/old_name/new_name/' &gt; new_update_via_sed.sh   in my program.  But I want to use variables, e.g.  old_run='old_name_952' new_run='old_name_953'   I have tried using them but the substitution doesn't happen (no error). I have tried:  cat update_via_sed.sh | sed 's/old_run/new_run/' cat update_via_sed.sh | sed 's/$old_run/$new_run/' cat update_via_sed.sh | sed 's/${old_run}/${new_run}/'
100466
0:root@SERVER:/root # echo "something" | sed -e 's/^/\t/g' tsomething 0:root@SERVER:/root #    AIX/ksh .. why doesn't it works? I just want to put a "tab" before every line!
35787
Say I have this file:  hello world hello world   This program  #!/bin/bash  for i in $(cat $1); do     echo "tester: $i" done   outputs  tester: hello tester: world tester: hello tester: world   I'd like to have the for iterate over each line individually ignoring whitespaces though, i.e. the last two lines should be replaced by  tester: hello world   Using quotes for i in "$(cat $1)"; results in i being assigned the whole file at once. What should I change?
51359
IT seems that 'sed' and I will never be friends...  How can I find and replace a pattern within a range (within another pattern)?  In words: Find: AllowOverride None within the following range and replace it with AllowOverride All  ... &lt;Directory "/var/www/html"&gt; some text more text some comments AllowOverride None more text &lt;/Directory&gt; ...   Please note (if not already done): This is related to httpd.conf which contains a lot more "modules" all ending with &lt;/Directory&gt;  As this command is used within a yaml file, it would be aesome to achieve this with a one-liner (I am aware, that one-liners are getting ugly pretty fast...).   Also: I rely on using sed (requirement, dont ask me why - pls :))
6438
In my bash script I have an external (received from user) string, which I should use in sed pattern.  REPLACE="&lt;funny characters here&gt;" sed "s/KEYWORD/$REPLACE/g"   How can I escape the $REPLACE string so it would be safely accepted by sed as a literal replacement?  NOTE: The KEYWORD is a dumb substring with no matches etc. It is not supplied by user.
91376
Is this possible? I read somewhere that the following command would do it:     sed -e [command] [file]   but it appeared to do the same thing as just     sed [command] [file]   (it did not save the changes). Is there any way to do this using sed?
87431
I use sed -n '/string/,$p' file &gt;&gt; otherfile to copy text from a line with certain string to another file.  Now I want the copied text to be deleted in the original file. I tried different methods with sed and awk but nothing worked.  How to use sed to delete the text of a file from the beginning line with a certain string in it?  texta  texta1  textb    &lt;- string, delete rest of the text from here  textb1  textc  textc1   or would it be easier to cut instead of copying with sed and what would be the command instead?
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?
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 */.
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/'
11588
I'm trying to use Bash string substitution to combine an array. Desired output: cat,dog,fish  This works, but isn't there a way to do with without piping? #!/bin/bash  words=(cat dog fish)  echo &quot;${words[@]}&quot; | sed 's/ /,/g'  I've been trying this, which doesn't work. echo &quot;${words[@]// /,/}&quot;
87408
Oh, hi; So I've got this big json file and I'm trying to find and replace a few things but when I've used sed I get an error and I need a sed or awk string to find and replace it, without getting an error.  prajwal  Current: {&quot;telephone_numbers&quot;:[&quot;1-  Future: {&quot;telephone_numbers&quot;:[&quot;+1-  This is the command i tried and the error i got. sed -i 's/{&quot;telephone_numbers&quot;:[&quot;1-/{&quot;telephone_numbers&quot;:[&quot;+1-/g' output.json sed: -e expression #1, char 56: unterminated `s' command
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?
6111
I have a file that contains file names. For example:  /tmp/list.txt (it is with the spaces at the start of each line):     /tmp/file.log   /app/nir/home.txt   /etc/config.cust   I want, using one line, to move all the files listed in /tmp/list.txt to /app/dest  So it should be something like this:  cat /tmp/list.txt | xargs mv /app/dest/
80748
I have a file like this: 1 22 1 4 $3 3 5556 $33 $233 $1 5  I want to move all the lines starting with $ to the previous line by replacing the newline characters with a space. My result should look something like: 1 22 1 4 $3 3 5556 $33 $233 $1 5  How can I do it using sed or grep or awk?
72476
My current best bet is:  for i in $(find . -name *.jpg); do echo $i; done   Problem: does not handle spaces in filenames.   Note: I would also love a graphical way of doing this, such as the "tree" command.
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