I have text file DollarToPound.txt with some Dollar signs ($) please provide a shell script to replace dollar symbol with Pound(£) with sed command.  iam getting command garbled error!!!  please help. Operating system used-- solaris 10
123347
I have file test_output_archive.svd with some Dollar signs ($). I have generated a shell script Replace_dollar_pound.sh with cat command to replace dollar symbol with Pound (£) script is working on Solaris 10, Dollar getting replaced as expected. In Solaris 11, but the dollar is not getting replaced, not throwing any errors  Content of test_output_archive.svd : Line Rental $9  OOB Only for $10  Replace Dollar symbol with Pound at step1, Remove junk charactes at step 2, Remove temp file at step3, Rename at step4**  Content of Replace_dollar_pound.sh : cat test_output_archive.svd | tr "\044" "\243" > temp_archive.svd cat temp_archive.svd | tr -d "\302" > test_output_archive2.svd rm temp_archive.svd mv test_output_archive2.svd test_output_archive.svd  Any Modifications to be done as OS is updated to Solaris 11 ??
123931
It's high time to solve this conundrum that's been bothering me for years...  I've been meeting this from time to time and thought this is the way to go:  $(comm "$(arg)")   And thought my view was strongly supported by experience. But I'm not so sure anymore.  can't make up its mind too. It's both:  "$(dirname $0)"/stop.bash            ^-- SC2086: Double quote to prevent globbing and word splitting.   And:  $(dirname "$0")/stop.bash ^-- SC2046: Quote this to prevent word splitting.   What's the logic behind?   (It's Shellcheck version 0.4.4, btw.)
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?
18177
I have a text file containing this:  0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1   and I want to replace the 1.0 to 2.0 so that it becomes:  0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1   so I use this command:  sed -i 's/'1.0'/'2.0'/g' /home/user1/file1.txt   or this:  sed -i 's/1.0/2.0/g' /home/user1/file1.txt   but this is the result that appears and I don't know how to fix this:  0 0 -2.0 2.0 0 0 0 -2.0 0 1.5 0.0 2.0 1
104690
I want to sed using a variable.  For example, sed -n '1,10p' file. So, instead of 10, I want to use $k where k is an integer.
21921
I have a line as follows   // Testing this   I am trying to use a sed command to replace the // with a /* (sentence or word in between) */ on each line.  so it should look something like this  /* Testing this */   The first part is easy with calling  sed 's#//#/*#'   however, with the second part, I tried this solution    I tried with -e which gave me an error of 'unterminated s command'. Then, I tried with a semi colon to make it one so it was something along the lines of   's#//#/*#;#//#s#/$#*/#'   but all that seems to do is the first part (replacing // with /*)and not the second (putting a */ at the end of the same line).  What am I not doing correctly? Any pointers would be appreciated.
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?
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?
12938
What's the simplest way to do a find and replace for a given input string, say abc, and replace with another string, say XYZ in file /tmp/file.txt?  I am writting an app and using IronPython to execute commands through SSH &mdash; but I don't know Unix that well and don't know what to look for.  I have heard that Bash, apart from being a command line interface, can be a very powerful scripting language. So, if this is true, I assume you can perform actions like these.  Can I do it with bash, and what's the simplest (one line) script to achieve my goal?
33483
Preface: Every couple of days there comes a question of this type, which is easy to solve with sed, but takes time to explain. I'm writing this question and answer, so I can later refer to this generic solution and only explain the adaption for the specific case. Feel free to contribute.  I have files with variable definitions. Variables consist of uppercase letters or underscore _ and their values follow after the :=. The values can contain other variables. This is Gnom.def:  NAME:=Gnom FULL_NAME:=$FIRST_NAME $NAME FIRST_NAME:=Sman STREET:=Mainstreet 42 TOWN:=Nowhere BIRTHDAY:=May 1st, 1999   Then there is another file form.txt with a template form:  $NAME Full name: $FULL_NAME Address: $STREET in $TOWN Birthday: $BIRTHDAY Don't be confused by $NAMES   Now I want a script which replaces the variables (marked with $ and the identifier) in the form by the definitions in the other file, recursively, if necessary, so I get this text back:  Gnom Full name: Sman Gnom Address: Mainstreet 42 in Nowhere Birthday: May 1st, 1999 Don't be confused by $NAMES   The last line is to ensure that no substrings of variables get replaced accidentally.
70196
What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want to organize them neatly.  I kind of want to collect all substituend-substituent pairs in a file dictionary.txt in an easy-to-manage way, since I need to replace a lot of stuff, say like:  "yes"      : "no" "stop"     : "go, go, go!" "wee-ooo"  : "ooooh nooo!" "gooodbye" : "hello"  "high"     : "low" "why?"     : "i don't know"   Now I want to apply these substitutions in some file novel.txt.  Then I want to run magiccommand --magicflags dictionary.txt novel.txt so that all instances of yes in novel.txt are replaced by no (so even Bayesian would be replaced by Banoian) and all instances of goodbye in novel.txt would be replaced by hello and so forth.  So far, the strings I need to replace (and replace with) do not have any quotes (neither single nor double) in them. (It would be nice, though, to see a solution working well with strings containing quotes, of course.)  I know sed and awk / gawk can do such stuff principally, but can they also work with such dictionary files? Seems like gawk would be the right candidate for magiccommand, what are the right magicflags? How do I need to format my dictionary.txt?
68015
I am looking for a bash command that will multiply only numbers from a text file. Below is the content of my text file. I need multiply all numbers by 100.      0 4530000 sil 4530000 11100000 ow 11100000 6320000 p 6320000 7600000 ah 7600000 8410000 n 8410000 12100000 sil   For single line with only number,I am using something like this below  for file in *.txt; \ do y=`sed -n '1 p' "$file"`;    z=$(bc&lt;&lt;&lt;"$y*100")    sed $file -i -e 's/'"$y"'/'"$z"'/' done   But I dont know how to do it for multiple lines, with alphabets in them. Number of lines in my file are not fixed, each file has different number of lines with max being 8
99125
After running this code  #!/bin/bash rm -f myfile myfile-individual echo "Greetings, foobar!" &gt; myfile MYSTRING="Jack" cat myfile | sed 's:foobar:$MYSTRING:' &gt; myfile-individual   we end up with   Greetings, $MYSTRING!   in myfile-individual.  What should be the (sed/bash) script for the output to be instead  Greetings, Jack!
104860
I am trying to delete two lines ( 7 and 8) from a .txt file. For this I am using following code:-  #!/bin/sh Column="7" sed '"$Column",8d' myfile.txt &gt; result.txt   on running this script, I am getting this error:-  sed: -e expression #1, char 1: unknown command: `"'   Please tell me how to use variable as a part of sed command.
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.
31657
I found line sed 's~ ~~g' in a shell script on a Linux system. What is this ~?
71671
My script is:  n="y" while [ "{n}" = "y" ] if [ $n == "n" ]; then   break; fi echo "n is $n" do         read -p "Enter the word to find = " word         read -p "Enter word to replace = " replace         echo "$word n $replace"         #sed -i r.text.bak 's/$word/$replace/g' r.txt         sed -i "s/$word/$replace/g" "test.txt" echo "do you have further replacement? n or y" read temp n=$temp done   My problem is that I am also replacing partial matches. For example, for a line like this:  1.1.1.14 1.1.1.14567   I get this output:  1.1.1.3  1.1.1.3567   but I expected:  1.1.1.3 1.1.1.14567   How can I solve this?