I am trying to use sed in a bash file to add the following after it finds AddDefaultCharset UTF-8 &lt;IfModule mime_magic_module&gt;     MIMEMagicFile conf/magic &lt;/IfModule&gt;  To simplify things I am focusing just on adding the first line until I get it right, I have this so far..... sed '/AddDefaultCharset UTF-8/a &lt;IfModule mime_magic_module&gt;' /home/testfile.ini  But when I try running this it just echos out the entire file, where am I going wrong?
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?
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.
90073
I want to remove a character "[" from a file.  I tried   sed -i 's/[//g' 'filename'   however I get the following error      sed: -e expression #1, char 6: unterminated `s' command
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!
50223
I am running the following 2 sed commands. The first one adds newline characters where I want them, the second also adds newline characters where I want them, BUT also adds an extra one at the end of the file where there wasn't one before.  sed -e 's|\&lt;LIST_G_STATEMENT&gt;|&amp;\ |g' ${XMLDIR}/statement_tmp_1.xml &gt; ${XMLDIR}/statement_tmp_2.xml  sed -e 's|\&lt;/LIST_G_STATEMENT&gt;|&amp;\ |g' ${XMLDIR}/statement_tmp_2.xml &gt; ${XMLDIR}/statement_tmp_3.xml   Using od -c on all 3 of the files gives the following output.  statement_tmp_1.xml (no \n at end of file)  1314700    T   A   T   E   M   E   N   T   &gt;   &lt;   /   L   I   S   T   _ 1314720    G   _   S   T   A   T   E   M   E   N   T   &gt;   &lt;   /   G   _ 1314740    S   E   T   U   P   &gt;   &lt;   /   L   I   S   T   _   G   _   S 1314760    E   T   U   P   &gt;   &lt;   /   A   R   X   S   G   P   O   &gt; 1314777   statement_tmp_2.xml (no \n at end of file)  1314700    S   T   A   T   E   M   E   N   T   &gt;   &lt;   /   L   I   S   T 1314720    _   G   _   S   T   A   T   E   M   E   N   T   &gt;   &lt;   /   G 1314740    _   S   E   T   U   P   &gt;   &lt;   /   L   I   S   T   _   G   _ 1314760    S   E   T   U   P   &gt;   &lt;   /   A   R   X   S   G   P   O   &gt; 1315000   statement_tmp_3.xml (\n at end of file - where did it come from?)  1314700    S   T   A   T   E   M   E   N   T   &gt;   &lt;   /   L   I   S   T 1314720    _   G   _   S   T   A   T   E   M   E   N   T   &gt;  \n   &lt;   / 1314740    G   _   S   E   T   U   P   &gt;   &lt;   /   L   I   S   T   _   G 1314760    _   S   E   T   U   P   &gt;   &lt;   /   A   R   X   S   G   P   O 1315000    &gt;  \n 1315002   I am running AIX 5.3  Basically, I either want it to stop adding the extra \n, or find a way of removing it.
91670
I have a txt file like this John Doe;john Doe is ...;he lives in ... Mike Nelson;mike Nelson works for ...;he makes ... Marcy William;marcy's mother is ...;marcy travels a lot...   I want to convert every character following a semicolon to uppercase, so the final result is John Doe;John Doe is ...;He lives in ... Mike Nelson;Mike Nelson works for ...;He makes ... Marcy William;Marcy's mother is ...;Marcy travels a lot...  keeping the rest intact. This file contains accented letters and is coded in UTF-8. How do I do that using sed, awk or whatever using terminal? Thanks
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.
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
86465
For debugging purposes, I need to recursively search a directory for all files which start with a UTF-8 byte order mark (BOM). My current solution is a simple shell script:  find -type f | while read file do     if [ "`head -c 3 -- "$file"`" == $'\xef\xbb\xbf' ]     then         echo "found BOM in: $file"     fi done  Or, if you prefer short, unreadable one-liners:  find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done  It doesn't work with filenames that contain a line break, but such files are not to be expected anyway.  Is there any shorter or more elegant solution?  Are there any interesting text editors or macros for text editors?
19267
As in  I'm trying to get line numbers which contains the pattern. My pattern contains slashes so I wanted to add custom delimiter.  This simple one works:  sed -n '/file/=' temp.txt   Using delimiter for string replace works too:  sed 's|file|gile|' temp.txt   but when I want to add delimiter to first example it doesn't:  sed -n '|file /etc|=' temp.txt   I know I can escape slashes but I would prefer to add custom delimiter. Any idea how to fix my command?
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'
50152
Consider the following text (incidentally, part of a MySQL dump):   CREATE TABLE `table` (   `id` int(10) NOT NULL auto_increment,   `name` varchar(100) NOT NULL default '',   `description` text NOT NULL,   PRIMARY KEY  (`id`),   FULLTEXT KEY `full_index` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */;   I would like to remove the FULLTEXT key, and I also want to remove the trailing comma on the line above so that the SQL remains valid.  Can anyone come up with (and explain) a sed recipe to do this?
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.
83121
I am trying to replace multiple words in a file by using   sed -i #expression1 #expression2   file  Something  123 item1 Something  456 item2 Something  768 item3 Something  353 item4   Output (Desired)  anything  123 stuff1 anything  456 stuff2 anything  768 stuff3 anything  353 stuff4   Try-outs  I can get the following output by using sed -i two times.   sed -i 's/Some/any/g' file  sed -i 's/item/stuff/g' file   Can I have any possible way of making this as a single in-place command like   sed -i 's/Some/any/g' -i 's/item/stuff/g' file   When I tried the above code it takes s/item/stuff/g as a file and tries working on it.
16457
I'm writing a lecture with many source codes for example. The codes are stored in severus different files. I use listing and minted packages for formatting the sources.  I would like add character at the begin of every line of some codes like:   Bash shell ($ or #) Python shell (>>>) Matlab (>>) Other shells (>)   I tried some solutions which have given on:       But both solutions have the same problem when I try:  \begin{foo_environment}      \input{bar.txt}  \end{foo_environment}   In both solutions the linebreaking are ingnored  I have tried executing a bash command:  sed 's/^/$ /' bar.sh &gt; bar.txt   This works locally but I can't do the same in  and   This is a sample code bar.sh:  cd .. mount /dev/sda3 /mnt/ cd ~/.ssh/ ll cd ~ ls -al   The result must be:  $ cd .. $ mount /dev/sda3 /mnt/ $ cd ~/.ssh/ $ ll $ cd ~ $ ls -al
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
8304
I have    Input:           NISHA =\455     Output:   NISHA = 455   I want to remove \ from output. I tried to use command sed "s/[\]//g" P but it is not working and it flags an error:  character found after backslash is not meaningful